1 23 24 package org.apache.slide.util.logger.jdk14; 25 26 import java.io.PrintWriter ; 27 import java.io.StringWriter ; 28 import java.util.logging.Level ; 29 import java.util.logging.LogRecord ; 30 31 35 public class ConsoleLogfileFormatter extends java.util.logging.Formatter { 36 37 public String format(LogRecord record) { 38 boolean highlight = record.getLevel().intValue() > Level.INFO.intValue(); 40 StringBuffer message = new StringBuffer (); 41 42 if (highlight) message.append("\n"); 43 message.append(record.getSequenceNumber()); 44 message.append(" "); 45 message.append(record.getLevel()); 46 message.append(" "); 47 if (highlight) message.append("\n"); 48 message.append(record.getLoggerName()); 49 message.append(" - "); 50 message.append(formatMessage(record)); 51 message.append("\n"); 52 if (record.getThrown() != null) { 53 try { 54 StringWriter sw = new StringWriter (); 55 PrintWriter pw = new PrintWriter (sw); 56 record.getThrown().printStackTrace(pw); 57 pw.close(); 58 message.append(sw.toString()); 59 } catch (Exception ex) { 60 } 61 } 62 if (highlight) message.append("\n"); 63 64 return message.toString(); 65 } 66 } 67 | Popular Tags |