# PatternLayout lets you specify the output format according to conversion patterns similar to the C language printf function. For example, PatternLayout with the conversion pattern %r [%t] %-5p %c - %m%n will output something like:
176 [main] INFO org.foo.Bar - Located nearest gas station.
* The first field is the number of milliseconds elapsed since the start of the program.
* The second field is the thread making the log request.
* The third field is the priority of the log statement.
* The fourth field is the name of the category associated with the log request.
* The text after the '-' is the message of the statement.
# You can insert any literal text within the conversion pattern.
# Conversion characters are:
* %m: Outputs your message.
* %p: Outputs the priority of the logging event.
* %r: Outputs the number of milliseconds elapsed since the start of the application until the creation of the logging event.
* %c: Outputs the category of the logging event. Example: For the category name "a.b.c", the pattern %c{2} will output "b.c". {2} means "output last two components of the dot-separated category name". If no {n} is there, full Category name is output by default.
* %t: Outputs the name of the thread that generated the logging event.
* %x: Outputs the nested diagnostic context (NDC) associated with the thread that generated the logging event. Useful when multiple clients are handled by separate threads such as in Java servlets.
* %n: Outputs the platform-dependent newline character(s). Preferable to specifying "\n" or "\r\n" etc.
* %%: Outputs a single percent sign.
* WARNING: The patterns below will slow down the execution of your program somewhat. Avoid unless execution speed is not an issue.
* %d: Outputs the date of the logging event. The date conversion specifier may be followed by a date format specifier enclosed between braces. 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 admits the same syntax as the time pattern string of Java's SimpleDateFormat which is slow. For faster performance, use %d{ISO8601}, %d{ABSOLUTE}, %d{RELATIVE} (millisecs since program start, fastest) or %d{DATE} which use log4j's ISO8601DateFormat, AbsoluteTimeDateFormat, RelativeTimeDateFormat and DateTimeDateFormat date formatters respectively.
* %l: Outputs source code location information. Shortcut for %C.%M(%F:%L).
* %C: Outputs the fully-qualified class name of the caller issuing the logging request. Example: For the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass". {1} means "output last one component of the fully-qualified class name". If no {n} is there, full class name is output by default.
* %M: Outputs the method name where the logging request was issued.
* %F: Outputs the file name where the logging request was issued.
* %L: Outputs the line number from where the logging request was issued.
Partager