Link: http://blog.csdn.net/guoquanyou/article/details/5689652
Do the project is log4j output format parameters annoying, simply put the relevant parts of the API 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 the logger namespace, and if you add the {< layer, the name space that lists the specified number of layers from the 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 name space length is less than 20, then the left is padded with a space) |
%-20c |
(If the name space length is less than 20, then the right with a space padding) |
%.30c |
(If the name space is longer than 30, the extra characters are truncated) |
%20.30c |
(If the name space length is less than 20, then the left is padded with a space; If the name space is longer than 30, the extra characters are truncated) |
%-20.30c |
(If the name space length is less than 20, then the right is padded with a space; If the name space is longer than 30, the extra characters are truncated) |
%c |
Lists the full name of the class that called logger (including the package path) |
Suppose the current class is "Org.apache.xyz.SomeClass" |
%c |
Org.apache.xyz.SomeClass |
%c{1} |
SomeClass |
%d |
Show logging time,{< date format using 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 calling logger |
%F |
Myclass.java |
%l |
The location where the output log event occurred, including the class name, the thread that occurred, and the number of lines in the code |
%l |
Myclass.main (myclass.java:129) |
%l |
Show lines of code calling Logger |
%l |
129 |
%m |
Display output messages |
%m |
This is a message for debug. |
%m |
Displays the name of the method calling 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 program was started and when the log was logged |
%r |
1215 |
%t |
Output the name of the thread that generated the log event |
%t |
MyClass |
%x |
Press NDC (Nested diagnostic context, thread stack) Order output log |
Suppose that the order of a program invocation 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 |
Logs are output by MDC (mapped diagnostic context, thread mapping table). It is commonly used for multiple clients to connect to the same server, which makes it easier for the server to differentiate between the logs that the client accesses. |
%X{5} |
(Log of the client with code number 5) |
%% |
Show a percent semicolon |
%% |
% |
Here are a few examples of this, such as the log4j.properties content:
#log4j Config Log4j.rootlogger=debug,output
Log4j.appender.output.layout=org.apache.log4j.patternlayout Log4j.appender.output.layout.conversionpattern=%d{date}%-4r [%t]%-5p%c%x-%m%n ...... |
Then one possible output is:
OCT 22:23:30,117 0 [main] INFO myapp-entering application.
......
OCT 22:23:30,162 [main] INFO myapp-exiting application.
Excerpt from: http://blog.gceclub.sun.com.cn/index.php?op=ViewArticle&articleId=734&blogId=6