    001    package calhoun.util;
    002
    003
    004    import java.io.PrintWriter;
    005    import java.io.StringWriter;
    006    import java.text.SimpleDateFormat;
    007    import java.util.Date;
    008    import java.util.logging.Formatter;
    009    import java.util.logging.LogRecord;
    010
    011    /** Simpler formatter than the default Java SimpleFormatter.  Only displays time and file.
    012     */
    013    public class SimplerFormatter extends Formatter {
    014
    015            static SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
    016            static String blanks="       ";
    017
    018            /** Just prints a time followed by message followed by class function line
    019             */
    020            @Override
    021            public String format(LogRecord rec) {
    022                    String l= rec.getLevel().getName();
    023                    String err = "";
    024                    Throwable t = rec.getThrown();
    025                    if(t != null) {
    026                            err = t.getMessage() + ": "+printStackTrace(t);
    027                    }
    028                    return f.format(new Date(rec.getMillis()))+blanks.substring(0, 7-l.length())
    029                    +l+" "+rec.getLoggerName()+"."+rec.getSourceMethodName()+" - "+rec.getMessage()+"\n"+err;
    030            }
    031
    032            private String printStackTrace(Throwable t) {
    033                    StringWriter sw = new StringWriter();
    034                    t.printStackTrace(new PrintWriter(sw, true));
    035                    return sw.toString().replaceAll("\\p{Blank}*at org.python.core.*\n", "");
    036            }
    037    }