1 16 17 package examples; 18 19 import org.apache.log4j.*; 20 import org.apache.log4j.helpers.PatternParser; 21 22 38 public class MyPatternLayout extends PatternLayout { 39 public 40 MyPatternLayout() { 41 this(DEFAULT_CONVERSION_PATTERN); 42 } 43 44 public 45 MyPatternLayout(String pattern) { 46 super(pattern); 47 } 48 49 public 50 PatternParser createPatternParser(String pattern) { 51 return new MyPatternParser( 52 pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern); 53 } 54 55 public 56 static void main(String [] args) { 57 Layout layout = new MyPatternLayout("[counter=%.10#] - %m%n"); 58 Logger logger = Logger.getLogger("some.cat"); 59 logger.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT)); 60 logger.debug("Hello, log"); 61 logger.info("Hello again..."); 62 } 63 } 64 | Popular Tags |