1 package org.jzonic.jlo.formatter; 2 3 import org.jzonic.jlo.LogRecord; 4 import java.text.SimpleDateFormat ; 5 import java.util.Date ; 6 import java.util.Map ; 7 21 public class DefaultFormatter extends AbstractFormatter { 22 25 public DefaultFormatter(String configName) { 26 super(configName); 27 } 28 29 30 34 public String formatMessage(LogRecord lr) { 35 SimpleDateFormat formatter = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss - "); 36 Date currentTime = new Date (); 37 String dateString = formatter.format(currentTime); 38 StringBuffer sb = new StringBuffer (); 39 sb.append(dateString); 40 if ( lr.getElapsed() != -1 ) { 41 sb.append(" [ellapsed: "); 42 sb.append(lr.getElapsed()); 43 sb.append("ms] "); 44 } 45 String ndc = lr.getNDC(); 46 if ( ndc != null ) { 47 sb.append(ndc); 48 sb.append(" "); 49 } 50 if (lr.getTarget() != null) { 51 sb.append("["); 52 sb.append(lr.getTarget().getName().toUpperCase()); 53 sb.append("] "); 54 } 55 String callerLine = lr.getSourceClassName(); 56 if ( callerLine != null ) { 57 sb.append("["); 58 sb.append(callerLine); 59 sb.append("] "); 60 } 61 if (lr.getMessage() != null) { 62 sb.append(lr.getMessage()); 63 } 64 if ( lr.getThrown() != null ) { 65 sb.append(":"); 66 sb.append(lr.getStackTrace()); 67 } 68 return sb.toString(); 69 } 70 71 public void setParameter(Map params) { 72 } 74 } 75 | Popular Tags |