1 package de.webman.util.log4j; 2 3 import org.apache.log4j.*; 4 import org.apache.log4j.helpers.PatternParser; 5 import org.apache.log4j.spi.LoggingEvent; 6 7 14 public class WebmanPatternLayout extends PatternLayout 15 { 16 final static int DEFAULT_BUFFER_SIZE = 128; 17 StringBuffer sbuf = new StringBuffer (DEFAULT_BUFFER_SIZE); 18 public WebmanPatternLayout() { 19 this(DEFAULT_CONVERSION_PATTERN); 20 } 21 22 public WebmanPatternLayout(String pattern) { 23 super(pattern); 24 } 25 26 public PatternParser createPatternParser(String pattern) 27 { 28 return new WebmanPatternParser( 29 pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern); 30 } 31 32 public 33 String format(LoggingEvent event) { 34 35 sbuf.setLength(0); 36 sbuf.append(event.priority.toString()); 37 sbuf.append(" - "); 38 sbuf.append(event.getMessage()); 39 sbuf.append(LINE_SEP); 40 return sbuf.toString(); 41 } 42 45 public boolean ignoresThrowable() 46 { 47 return false; 48 } 49 50 public 51 static void main(String [] args) { 52 Layout layout = new WebmanPatternLayout("[exception=%#] - %m%n"); 53 Category cat = Category.getInstance("some.cat"); 54 cat.addAppender(new ConsoleAppender(layout)); 55 Exception e = new Exception ("text"); 56 cat.debug("Hello, log", e); 58 cat.info("Hello again...", e); 59 } 60 } 61
| Popular Tags
|