The most flexible of all the API provided Layout objects, it applies printf like formatting to the output allowing you to include or exclude options like the logger name, date, log location, priority, NDC, MDC and of course your message. The API Documentation for it lists the /ConversionPattern conversion characters and their effects.

In addition to this built-in layout, likely candidates for console and syslog output include TTCCLayout and SimpleLayout. The layout is set per appender.

If the /ConversionPattern specifies fields that your code does not provide, like a NestedDiagnosticContexts or a line number, it may output a whatever the initial value of is for the object (like an empty string or -1). Your code needs to provide the data if you want to log it. Once it's provided you can choose to use it or not based on the configuration.

log4j.appender.C=org.apache.log4j.ConsoleAppender
log4j.appender.C.layout=org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern=%d{%Y-%m-%d %H:%M:%S} %-5p %c %x - %m%n

See Also

Mailing List


CategoryApiDocs

PatternLayout (last edited 2013-01-22 13:58:31 by Christian Boos)