1 16 17 20 package org.apache.log4j; 21 22 import org.apache.log4j.helpers.DateLayout; 23 import org.apache.log4j.spi.LoggingEvent; 24 25 73 public class TTCCLayout extends DateLayout { 74 75 private boolean threadPrinting = true; 77 private boolean categoryPrefixing = true; 78 private boolean contextPrinting = true; 79 80 81 protected final StringBuffer buf = new StringBuffer (256); 82 83 84 90 public TTCCLayout() { 91 this.setDateFormat(RELATIVE_TIME_DATE_FORMAT, null); 92 } 93 94 95 103 public TTCCLayout(String dateFormatType) { 104 this.setDateFormat(dateFormatType); 105 } 106 107 108 112 public 113 void setThreadPrinting(boolean threadPrinting) { 114 this.threadPrinting = threadPrinting; 115 } 116 117 120 public 121 boolean getThreadPrinting() { 122 return threadPrinting; 123 } 124 125 129 public 130 void setCategoryPrefixing(boolean categoryPrefixing) { 131 this.categoryPrefixing = categoryPrefixing; 132 } 133 134 137 public 138 boolean getCategoryPrefixing() { 139 return categoryPrefixing; 140 } 141 142 147 public 148 void setContextPrinting(boolean contextPrinting) { 149 this.contextPrinting = contextPrinting; 150 } 151 152 155 public 156 boolean getContextPrinting() { 157 return contextPrinting; 158 } 159 160 171 public 172 String format(LoggingEvent event) { 173 174 buf.setLength(0); 176 177 dateFormat(buf, event); 178 179 if(this.threadPrinting) { 180 buf.append('['); 181 buf.append(event.getThreadName()); 182 buf.append("] "); 183 } 184 buf.append(event.getLevel().toString()); 185 buf.append(' '); 186 187 if(this.categoryPrefixing) { 188 buf.append(event.getLoggerName()); 189 buf.append(' '); 190 } 191 192 if(this.contextPrinting) { 193 String ndc = event.getNDC(); 194 195 if(ndc != null) { 196 buf.append(ndc); 197 buf.append(' '); 198 } 199 } 200 buf.append("- "); 201 buf.append(event.getRenderedMessage()); 202 buf.append(LINE_SEP); 203 return buf.toString(); 204 } 205 206 212 public 213 boolean ignoresThrowable() { 214 return true; 215 } 216 } 217 | Popular Tags |