1 14 15 package org.quickserver.util.logging; 16 17 import java.util.logging.*; 18 import java.util.Date ; 19 import java.text.SimpleDateFormat ; 20 import org.quickserver.util.MyString; 21 22 26 public class SimpleConsoleFormatter extends Formatter { 27 private Date date = new Date (); 28 private SimpleDateFormat df = new SimpleDateFormat ("hh:mm:ss,SSS"); 29 private String lineSeparator = (String ) java.security.AccessController.doPrivileged( 30 new sun.security.action.GetPropertyAction("line.separator")); 31 32 public synchronized String format(LogRecord record) { 33 date.setTime(record.getMillis()); 34 35 StringBuffer sb = new StringBuffer (); 36 sb.append(df.format(date)); 37 sb.append(" ["); 38 sb.append(MyString.alignLeft(record.getLevel().getLocalizedName(), 7)); 39 sb.append("] "); 40 if(record.getSourceClassName() != null) { 41 sb.append(record.getSourceClassName()); 42 } else { 43 sb.append(record.getLoggerName()); 44 } 45 if(record.getSourceMethodName() != null) { 46 sb.append('.'); 47 sb.append(record.getSourceMethodName()); 48 } 49 sb.append(" - "); 50 sb.append(formatMessage(record)); 51 52 if(record.getThrown() != null) { 53 sb.append(lineSeparator); 54 sb.append("[Exception: "); 55 sb.append(record.getThrown().toString()); 56 sb.append(']'); 57 } 58 59 sb.append(lineSeparator); 60 return sb.toString(); 61 } 62 } 63 | Popular Tags |