[Favorite] log4j output log format patternlayout modifier

Source: Internet
Author: User
Tags modifier truncated log4j

The various configuration items in the output log format are described below:

Parameters Description Example
%c Lists the full name of the logger namespace, if the {< layer is added, the namespace that lists the specified number of layers from the most inner layer log4j configuration File Parameters Example Output Display Media
Suppose the current logger namespace is "A.B.C"
%c A.b.c
%C{2} B.c
%20c (If the namespace length is less than 20, the left is padded with spaces)
%-20c (If the namespace length is less than 20, the right side is padded with spaces)
%.30c (If the namespace is longer than 30, the extra characters are truncated)
%20.30c (If the namespace length is less than 20, the left is padded with spaces; If the namespace is longer than 30, the extra characters are truncated)
%-20.30c (If the namespace length is less than 20, the right side is filled with spaces; If the namespace is longer than 30, the extra characters are truncated)
%c Lists the full name of the class that called logger (contains the package path) Assuming the current class is "Org.apache.xyz.SomeClass"
%c Org.apache.xyz.SomeClass
%c{1} SomeClass
%d Displays the logging time,{< date format;} Use the date format defined by ISO8601 %d{yyyy/mm/dd Hh:mm:ss,sss} 2005/10/12 22:23:30,117
%d{absolute} 22:23:30,117
%d{date} OCT 2005 22:23:30,117
%d{iso8601} 2005-10-12 22:23:30,117
%F Displays the source file name of the call logger %F Myclass.java
%l Where the output log event occurs, including the class name, the thread that occurred, and the number of rows in the code %l Myclass.main (myclass.java:129)
%l Shows the line of code that called logger %l 129
%m Show output message %m A message for Debug.
%M Shows the name of the method that called logger %M Main
%n Line breaks under the current platform %n The RN is represented under Windows platform
The Unix platform represents N
%p Show priority for this log %p INFO
%r Displays the number of milliseconds that have elapsed since the start of the program to record the log %r 1215
%t Output the name of the thread that generated the log event %t MyClass
%x Output logs in order by NDC (Nested Diagnostic Context, thread stack) Assume that a program call order is MyApp call Com.foo.Bar
%c%x-%m%n Myapp-call Com.foo.Bar.
Com.foo.bar-log in Bar
Myapp-return to MYAPP.
%x Press the MDC (Mapped Diagnostic Context, Thread mapping table) to output the log. Typically used for multiple clients to connect to the same server, which makes it easier for the server to differentiate between the logs that client access leaves behind. %X{5} (Log of the client logged with the code number 5)
%% Display a percent semicolon %% %

LOG4J 1.2 official version: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

Log4j 2.x official version: Https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns

You will need to check the official version for your own travel.

Above icon reproduced from: http://blog.csdn.net/yang3wei/article/details/46991547

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.