1 28 29 package com.caucho.log; 30 31 import com.caucho.vfs.StringWriter; 32 import com.caucho.vfs.WriteStream; 33 34 import java.util.logging.Formatter ; 35 import java.util.logging.LogRecord ; 36 37 41 public class MessageFormatter extends Formatter { 42 public String format(LogRecord record) 43 { 44 return formatMessage(record); 45 } 46 47 65 public String formatMessage(LogRecord record) 66 { 67 String message = super.formatMessage(record); 68 Throwable thrown = record.getThrown(); 69 70 try { 71 if (thrown != null) { 72 StringWriter sw = new StringWriter(); 73 WriteStream os = sw.openWrite(); 74 75 if (message != null && 76 ! message.equals(thrown.toString()) && 77 ! message.equals(thrown.getMessage())) 78 os.println(message); 79 80 Throwable rootExn = thrown; 81 82 for (; 83 rootExn != null && rootExn.getCause() != null; 84 rootExn = rootExn.getCause()) { 85 } 86 87 rootExn.printStackTrace(os.getPrintWriter()); 88 89 message = sw.getString(); 90 } 91 } catch (Throwable e) { 92 e.printStackTrace(); 93 } 94 95 return message; 96 } 97 } 98 99 | Popular Tags |