Layout Formats

The layout specifies how the output is formatted before it is sent to the output device. The layout is specified as a pattern string. The following table shows the characters available for use within layout pattern strings:
The following table shows the special conversion characters available for use within layout pattern strings:
Conversion Characters for Layout Patterns
Conversion Character
Result
c
Used to output the logging context. The logging context conversion specifier can be followed by precision specifier, that is a decimal constant in brackets or braces. The precision specifier specifies the number of rightmost components of the logging context name that will be printed. For example, for the logging context name a.b.c the pattern %c{2} outputs b.c.
If you do not specify a precision specifier, the logging context name is printed in full.
d
Used to output the date of the logging event. The date conversion specifier can be followed by a date format specifier enclosed between braces. For example, %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date format specifier is given, then ISO8601 format is assumed.
l
Used to output location information of the caller that generated the logging event. The location information depends on the JVM implementation, but usually consists of the fully qualified name of the calling method followed by the caller's source, the filename, and line number all within parentheses. The location information can be very useful, but its generation can cause performance issues.
m
Used to output the application-supplied message that is associated with the logging event.
n
Used to output the platform-dependent line separator characters. This conversion character offers similar performance to using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator.
p
Used to output the priority of the logging event.
r
Used to output the number of milliseconds elapsed since the start of the application until the creation of the logging event.
s
Used to output the session ID that is associated with this logging event. The output for this conversion character is an empty string if the Logger being used does not have an associated SessionContext.
t
Used to output the name of the thread that generated the logging event.
u
Used to output the user name that is associated with this logging event. The output for this conversion character is an empty string if the Logger being used does not have an associated SessionContext, or if that SessionContext does not have an associated UserContext.
%
The sequence %% outputs a single percent sign.
For more information about layout formats, see the log4j documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html on the Apache Web site.