previous next TOC

Layouts & ObjectRenderers
 
  • Users can customize the output of an appender by associating with it a Layout.

  • The PatternLayout formats a logging event according to a conversion pattern.
  • Logging output can be formatted also in HTML or XML among other formats.
  • It is also possible to format the output by message object type by registering an appropriate ObjectRenderer for a given type.

For example, the conversion pattern "%r [%t] %-5p %c - %m%n" will output something akin to:

    176 [main] INFO  org.foo.Bar - Located nearest gas station. 

where the first field is the number of milliseconds elapsed since the start of the application, the second field is the thread making the log request, the third field is the level of the log statement, The fourth field is the name of the logger associated with the log request and the text after the '-' is the message of the statement

Layouts act on the logging event data, such as the calling thread, date and time information, invoked logger and the message string, whereas object rendering acts only on the message object transforming it to a string based on type.

 

GET THE DOCS DIRECTLY FROM THE DEVELOPER
For up to date and detailed log4j documentation directly from the developer please consider The complete log4j manual.