1 5 6 package org.joseki.logging.java; 7 8 import java.io.* ; 9 import java.util.logging.*; 10 11 18 19 public class OneLineFormatterCompact extends Formatter 20 { 21 static public int nameColWidth = 30 ; 23 24 private String lineSeparator = 27 (String ) java.security.AccessController.doPrivileged( 28 new sun.security.action.GetPropertyAction("line.separator")); 29 30 35 public synchronized String format(LogRecord record) 36 { 37 StringBuffer sb = new StringBuffer (); 38 39 if ( ! record.getLevel().equals(Level.INFO)) 40 { 41 sb.append(record.getLevel().getLocalizedName()); 42 sb.append(": "); 43 } 44 45 49 if (record.getSourceClassName() != null) 50 { 51 if (!record.getSourceClassName().equals("")) 52 { 53 String str = record.getSourceClassName(); 54 int i = str.lastIndexOf('.'); 55 if (i >= 0) 56 sb.append(str.substring(i + 1)); 57 else 58 sb.append(str) ; 59 } 60 } 61 62 if ( record.getSourceMethodName() != null ) 63 { 64 sb.append("."); 65 sb.append(record.getSourceMethodName()); 66 } 67 68 sb.append(": ") ; 69 70 if ( record.getLevel().equals(Level.WARNING) || 71 record.getLevel().equals(Level.SEVERE) ) 72 { 73 sb.append(record.getLevel().getLocalizedName()) ; 74 sb.append(" :: ") ; 75 } 76 77 78 String message = formatMessage(record); 79 sb.append(message); 80 81 83 if (record.getThrown() != null) 84 { 85 try 86 { 87 StringWriter sw = new StringWriter(); 88 PrintWriter pw = new PrintWriter(sw); 89 record.getThrown().printStackTrace(pw); 90 pw.close(); 91 sb.append(lineSeparator); 92 sb.append(sw.toString()); 93 } 94 catch (Exception ex) 95 { 96 } 97 } 98 return sb.toString(); 99 } 100 } 101 102 128 129 | Popular Tags |