1 19 package org.openharmonise.rm.logging; 20 21 import java.util.logging.*; 22 import java.util.*; 23 24 33 public class HarmoniseFormatter extends XMLFormatter { 34 35 38 public HarmoniseFormatter() { 39 super(); 40 } 41 42 50 private void escape(StringBuffer sb, String text) { 51 if (text == null) { 52 text = "<null>"; 53 } 54 sb.append(text); 55 } 56 57 60 public String format(LogRecord record) { 61 StringBuffer sb = new StringBuffer (500); 62 sb.append("<record>\n"); 63 64 sb.append(" <date>"); 65 sb.append(new Date(record.getMillis())); 66 sb.append("</date>\n"); 67 68 sb.append(" <millis>"); 69 sb.append(record.getMillis()); 70 sb.append("</millis>\n"); 71 72 sb.append(" <sequence>"); 73 sb.append(record.getSequenceNumber()); 74 sb.append("</sequence>\n"); 75 76 String name = record.getLoggerName(); 77 if (name != null) { 78 sb.append(" <logger>"); 79 escape(sb, name); 80 sb.append("</logger>\n"); 81 } 82 83 sb.append(" <level>"); 84 escape(sb, record.getLevel().toString()); 85 sb.append("</level>\n"); 86 87 if (record.getSourceClassName() != null) { 88 sb.append(" <class>"); 89 escape(sb, record.getSourceClassName()); 90 sb.append("</class>\n"); 91 } 92 93 if (record.getSourceMethodName() != null) { 94 sb.append(" <method>"); 95 escape(sb, record.getSourceMethodName()); 96 sb.append("</method>\n"); 97 } 98 99 sb.append(" <thread>"); 100 sb.append(record.getThreadID()); 101 sb.append("</thread>\n"); 102 103 if (record.getMessage() != null) { 104 String message = formatMessage(record); 106 sb.append(message); 107 } 108 109 sb.append("</record>\n"); 110 return sb.toString(); 111 } 112 } 113 | Popular Tags |