import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class ErrorLog
{
private static ErrorLog singleton=new ErrorLog();
private PrintWriter writer;
private static SimpleDateFormat sdf = null;
private static String dateaTime = null;
private ErrorLog()
{
String dirPath="D:/tests";
try
{
if (dirPath!=null)
{
writer = new PrintWriter(new FileOutputStream("D:/tests/file.log", true), true);
}
else
{
System.out.println("Fatal error, can~t create error log.");
}
}
catch (IOException exp)
{
System.out.println("Fatal error, can~t create error log - "+exp.getMessage());
exp.printStackTrace();
}
}
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
public static synchronized void log(String toLog)
{
try
{
sdf = new SimpleDateFormat("yyyy~ ~MM~ ~dd~ ~ hh:mm:ss aaa");
dateaTime = sdf.format((Calendar.getInstance().getTime()));
System.out.println("dateaTime"+dateaTime);
singleton.writer.write(dateaTime+" --> ");
singleton.writer.write(toLog);
singleton.writer.write("\n");
singleton.writer.flush();
}
catch (Exception exp)
{
System.out.println("Fatal error, can~t write to log - "+exp.getMessage());
exp.printStackTrace();
}
}
}
/*
usage: ErrorLog.log("my string message");
*/
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">