FileDocCategorySizeDatePackage
MyPatternLayout.javaAPI DocApache log4j 1.2.152013Sat Aug 25 00:09:34 BST 2007org.apache.log4j

MyPatternLayout

public class MyPatternLayout extends PatternLayout
Example showing how to extend PatternLayout to recognize additional conversion characters.

In this case MyPatternLayout recognizes %# conversion pattern. It outputs the value of an internal counter which is also incremented at each call.

See source code for more details.

see
MyPatternParser
see
org.apache.log4j.PatternLayout
author
Anders Kristensen

Fields Summary
Constructors Summary
public MyPatternLayout()

    this(DEFAULT_CONVERSION_PATTERN);
  
public MyPatternLayout(String pattern)

    super(pattern);
  
Methods Summary
public org.apache.log4j.helpers.PatternParsercreatePatternParser(java.lang.String pattern)

    return new MyPatternParser(
      pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern);
  
public static voidmain(java.lang.String[] args)

    Layout layout = new MyPatternLayout("[counter=%.10#] - %m%n");
    Logger logger = Logger.getLogger("some.cat");
    logger.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
    logger.debug("Hello, log");
    logger.info("Hello again...");