Previous Log Messages Next

Conversion Characters

The characters that The patterns are case-sensitive.
Conversion Characters  

Conversion

Character

Effect

%c

The category of the logging event. The category conversion specifier can be optionally followed by a precision specifier, which is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right-most components of the category name will be printed. By default, the category name is printed in full.

For example, for the category name "a.b.c" the pattern %c{2} will output "b.c".

%C

The fully-qualified class name of the caller issuing the logging request. This conversion specifier can be optionally followed by a precision specifier, which is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right-most components of the class name will be printed. By default the class name is output in fully-qualified form.

For example, for the class name "org.apache.xyz.SomeClass" the pattern %C{1} will output "SomeClass".

WARNING: Generating the caller class information is slow. Its use should be avoided unless execution speed is not an issue.

%F

The file name where the logging request was issued.

WARNING: Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.

%d

The date of the logging event. The date conversion specifier may 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.

The date format specifier uses the same syntax as the time pattern string of the SimpleDateFormat. Although part of the standard JDK, the performance of SimpleDateFormat is quite poor.

For better results it is recommended to use the log4j date formatters. These can be specified using one of the strings ABSOLUTE, DATE and ISO8601 for specifying AbsoluteTimeDateFormat, DateTimeDateFormat, and ISO8601DateFormat respectively. For example, %d{ISO8601} or %d{ABSOLUTE}.

These dedicated date formatters perform significantly better than SimpleDateFormat.

%l

Location information of the caller which 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 file name and line number between parentheses.

The location information can be very useful. However, its generation is extremely slow. Its use should be avoided unless execution speed is not an issue.

%L

The line number from where the logging request was issued.

WARNING: Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.

%m

The application-supplied message associated with the event being logged.

%M

The name of the method where the logging request was issued.

WARNING: Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue.

%p

The priority of the logging event.

%r

The number of milliseconds elapsed since the start of the application and the time of creation of the logging event.

%t

The name of the thread that generated the logging event.

%x

The NDC (nested diagnostic context) associated with the thread that generated the logging event.

%n

A platform-dependent new line character (usually included at the end of each logging pattern, to force one message per line in the log file).

This conversion character offers practically the same performance as using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator.

%%

A single percent sign (required to escape the percent sign).



Previous Log Messages Next