Log4j output format control-meaning of the patternlayout parameter of log4j

Source: Internet
Author: User
Tags truncated
Do the project is log4j output formatting parameters get bored, simply the relevant part of the API is roughly translated, the original see http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html
 

 
Parameters Description Example
% C Lists the full name of a logger namespace. If {<layers>} is added, the namespace of the specified number of layers counted from the innermost layer is listed. Example of parameters in the log4j configuration file Output Display Media
Assume that 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, fill the space on the left)
%-20C (If the namespace length is less than 20, the right side is filled with spaces)
%. 30C (If the namespace length exceeds 30, Remove extra characters)
% Limit 30C (If the namespace length is less than 20, spaces are filled on the left. If the namespace length exceeds 30, excessive characters are truncated)
%-Limit 30C (If the namespace length is less than 20, the right side is filled with spaces. If the namespace length exceeds 30, excessive characters are truncated)
% C Lists the full names (including the package path) of the classes that call logger) Assume that the current class is org. Apache. XYZ. someclass"
% C Org. Apache. XYZ. someclass
% C {1} Someclass
% D Displays the log record time. {<date format>} uses the date format defined in iso8601. % D {yyyy/mm/dd hh: mm: SS, SSS} 22:23:30, 117
% D {absolute} 22:23:30, 117
% D {date} 12 Oct 2005 22:23:30, 117
% D {iso8601} 22:23:30, 117
% F Display the name of the source file that calls Logger % F Myclass. Java
% L Location where the output log event occurs, including the category name, the thread that occurs, and the number of lines in the code % L Myclass. Main (myclass. Java: 129)
% L Display the code lines that call Logger % L 129
% M Display output messages % M This is a message for debug.
% M Display the method name for calling Logger % M Main
% N Line breaks on the current platform % N Rn in Windows
Indicates N in UNIX
% P Displays the priority of the log. % P Info
% R Displays the number of milliseconds that have elapsed since the program was started to record the log. % R 1215
% T Name of the thread that generates the log event % T Myclass
% X Output logs in NDC (nested diagnostic context, thread stack) Order Assume that the calling sequence of a program is MyApp calling com. Foo. Bar.
% C % x-% m % N MyApp-call com. Foo. Bar.
Com. Foo. Bar-log in bar
MyApp-return to MyApp.
% X Output logs by MDC (mapped diagnostic context, thread ing table. It is usually used for connecting multiple clients to the same server. It is convenient for the server to distinguish the logs left by the client. % X {5} (Logs of clients codenamed 5)
% Display a percent sign % %

 

For example, the content of log4j. properties is as follows:

# Log4j config
Log4j. rootlogger = debug, output

Log4j. appender. Output. layout = org. Apache. log4j. patternlayout
Log4j. appender. Output. layout. conversionpattern = % d {date} %-4r [% T] %-5 p % C % x-% m % N
......

 

One possible output is:

12 Oct 2005 22:23:30, 117 0 [main] info MyApp-entering application.
......
12 Oct 2005 22:23:30, 162 45 [main] info MyApp-exiting application.

From: http://blog.gceclub.sun.com.cn/index.php? OP = viewarticle & ArticleID = 734 & blogid = 6

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.