1 14 package org.wings.util; 15 16 import java.io.PrintWriter ; 17 import java.io.StringWriter ; 18 import java.text.DateFormat ; 19 import java.text.SimpleDateFormat ; 20 import java.util.Date ; 21 import java.util.logging.LogRecord ; 22 23 public class ExtendedFormatter 24 extends java.util.logging.Formatter { 25 private DateFormat dateFormatter; 26 27 public ExtendedFormatter() { 28 dateFormatter = new SimpleDateFormat ("MMM dd, yyyy hh:mm:ss a"); 29 } 30 31 public String format(LogRecord record) { 32 StringBuffer msg = new StringBuffer (); 33 msg.append(dateFormatter.format(new Date ())); 34 msg.append(" "); 35 msg.append(record.getLevel()); 36 msg.append(" "); 37 msg.append(record.getSourceClassName()); 38 msg.append(" "); 39 msg.append(record.getSourceMethodName()); 40 msg.append(": "); 41 msg.append(formatMessage(record)); 42 msg.append("\n"); 43 if (record.getThrown() != null) 44 msg.append(getBackTrace(record.getThrown())); 45 46 return msg.toString(); 47 } 48 49 protected String getBackTrace(Throwable theThrown) { 50 StringWriter sw = new StringWriter (); 51 PrintWriter pw = new PrintWriter (sw); 52 theThrown.printStackTrace(pw); 53 pw.close(); 54 return sw.getBuffer().toString(); 55 } 56 } 57 | Popular Tags |