log4j日志格式配置
所属分类 log4j
浏览量 1454
layout ConversionPattern
%m 输出代码中指定的消息
%p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL
%r 输出自应用启动到输出该log信息耗费的毫秒数
%c 输出所属的类目,通常就是所在类的全名
%t 输出产生该日志事件的线程名
%n 输出一个回车换行符,Windows平台为“rn”,Unix平台为“n”
%d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyyy MMM dd HH:mm:ss,SSS},输出类似:2002年10月18日 :10:28,921
%l 输出日志事件的发生位置,包括类目名、发生的线程,以及在代码中的行数。
%x Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event
%X Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event for specified key
%n - newline
%m - your log message
%p - message priority (FATAL, ERROR, WARN, INFO, DEBUG or custom)
%r - millisecs since program started running
%% - percent sign in output
%c - name of your category (logger), %c{2} will outputs last two components
%t - name of current thread
SLOW PERFORMANCE FORMATS
%d - date and time, also %d{ISO8601}, %d{DATE}, %d{ABSOLUTE},
%d{HH:mm:ss,SSS}, %d{dd MMM yyyy HH:mm:ss,SSS} and so on
%l - Shortcut for %F%L%C%M
%F - Java source file name
%L - Java source line number
%C - Java class name, %C{1} will output the last one component
%M - Java method name
log4j.properties
# log4j.rootLogger=info, stdout, file
log4j.rootLogger=info,file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=app.log
log4j.appender.file.MaxFileSize=10MB
# Keep one backup file
log4j.appender.file.MaxBackupIndex=3
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss,SSS} %p %t %c %l - %m %n
2019-四月-02 12:01:15,691 INFO qtp2134407557-19 dyyx.util.WebUtil dyyx.util.WebUtil.run(WebUtil.java:156) - 1554177015691_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2019-四月-02 12:01:16,144 INFO qtp2134407557-19 dyyx.util.WebUtil dyyx.util.WebUtil.run(WebUtil.java:156) - 1554177016144_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2019-四月-02 12:01:16,600 INFO qtp2134407557-19 dyyx.util.WebUtil dyyx.util.WebUtil.run(WebUtil.java:156) - 1554177016600_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
上一篇
下一篇
Linux文件操作相关知识点
linux硬链接和软链接的区别
linux文件中的inode
Class.forName()和ClassLoader.loadClass()的区别
getResource和getSystemResource的区别
spring常用注解