import java.io.IOException;
import java.io.PrintWriter;
import
java.io.StringWriter;
import java.util.Date;
import
java.util.logging.FileHandler;
import
java.util.logging.LogRecord;
import
java.util.logging.SimpleFormatter;
public class Logger {
private static FileHandler fh;
private static java.util.logging.Logger
logger;
public static class LogRecordFormatter extends SimpleFormatter {
public synchronized String format(LogRecord
record) {
Date dat = new Date();
dat.setTime(record.getMillis());
// String source;
// if (record.getSourceClassName() != null) {
// source =
record.getSourceClassName();
// if
(record.getSourceMethodName() != null) {
// source += " " +
record.getSourceMethodName();
// }
// } else {
// source =
record.getLoggerName();
// }
String message = formatMessage(record);
String throwable = "";
if
(record.getThrown() != null)
{
StringWriter sw = new
StringWriter();
PrintWriter pw = new
PrintWriter(sw);
pw.println();
record.getThrown().printStackTrace(pw);
pw.close();
throwable
= sw.toString();
}
return String.format("%1$s: [%2$tb %2$td, %2$tY
%2$tH:%2$tM:%2$tS %2$tL %2$tz]: %3$s%4$s%n",
record.getLevel().getName(),
dat,
message,
throwable);
}
}
static {
try {
logger = java.util.logging.Logger.getLogger("TimedReminder");
fh = new
FileHandler("%h/TimedReminder%g.log");
fh.setFormatter(new LogRecordFormatter());
logger.addHandler(fh);
} catch (SecurityException e)
{
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void info(final String msg) {
logger.log(java.util.logging.Level.INFO,
msg);
}
public static void warn(final String msg) {
logger.log(java.util.logging.Level.WARNING,
msg);
}
public static void infoe(final String msg, final Throwable ex) {
logger.log(java.util.logging.Level.INFO,
msg, ex);
}
}