1 package org.jzonic.jlo.formatter; 2 3 import org.jzonic.jlo.LogRecord; 4 5 import java.text.SimpleDateFormat ; 6 import java.util.Date ; 7 import java.util.Map ; 8 22 public class SimpleFormatter extends AbstractFormatter { 23 24 private String df = "yyyy/MM/dd HH:mm:ss - "; 25 28 public SimpleFormatter(String configName) { 29 super(configName); 30 } 31 32 36 public String formatMessage(LogRecord lr) { 37 SimpleDateFormat formatter = new SimpleDateFormat (df); 38 Date currentTime = new Date (); 39 String dateString = formatter.format(currentTime); 40 StringBuffer sb = new StringBuffer (); 41 sb.append(dateString); 42 if (lr.getTarget() != null) { 43 sb.append("["); 44 sb.append(lr.getTarget().getName().toUpperCase()); 45 sb.append("] "); 46 } 47 if (lr.getMessage() != null) { 48 sb.append(lr.getMessage()); 49 } 50 if ( lr.getThrown() != null ) { 51 sb.append(":"); 52 sb.append(lr.getStackTrace()); 53 } 54 return sb.toString(); 55 } 56 57 public void setParameter(Map params) { 58 if ( params.containsKey("date")) { 59 df = (String )params.get("date")+" - "; 60 } 61 } 62 } 63 | Popular Tags |