首页 > 代码库 > log4j输出模板
log4j输出模板
logger.info("1234567890");
1、log4j.properties文件如下
# Configure logging for testing: optionally with log file#\u53EF\u4EE5\u8BBE\u7F6E\u7EA7\u522B\uFF1Adebug>info>error#debug:\u53EF\u4EE5\u663E\u5F0Fdebug,info,error#info:\u53EF\u4EE5\u663E\u5F0Finfo,error#error:\u53EF\u4EE5\u663E\u5F0Ferrorlog4j.rootLogger=debug,appender1#log4j.rootLogger=info,appender1#log4j.rootLogger=error,appender1#\u8F93\u51FA\u5230\u63A7\u5236\u53F0log4j.appender.appender1=org.apache.log4j.ConsoleAppender#\u6837\u5F0F\u4E3ATTCCLayoutlog4j.appender.appender1.layout=org.apache.log4j.TTCCLayout
控制台结果
[main] INFO Client - 1234567890
无日志文件
2、log4j.properties文件如下
log4j.rootLogger=info, ServerDailyRollingFile, stdoutlog4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.ServerDailyRollingFile.DatePattern=‘.‘yyyy-MM-dd log4j.appender.ServerDailyRollingFile.File=logs/notify-subscription.log log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout log4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d - %m%n log4j.appender.ServerDailyRollingFile.Append=truelog4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} %p [%c] %m%n
控制台结果
2016-09-20 20:31:37 INFO [Client] 1234567890
log文件结果
2016-09-20 20:31:37,986 - 1234567890
红色为日志路径
3、log4j.properties文件如下
log4j.rootLogger=INFO,R,Clientlog4j.appender.R=org.apache.log4j.RollingFileAppenderlog4j.appender.R.File=./log/server.loglog4j.appender.R.MaxFileSize=5MBlog4j.appender.R.MaxBackupIndex=10log4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=[%5p] %d [%X{userName}] [%X{remoteIp}] %m%nlog4j.logger.Client=INFO,Clientlog4j.additivity.Client = falselog4j.appender.Client=org.apache.log4j.RollingFileAppenderlog4j.appender.Client.File=./log/client.loglog4j.appender.Client.MaxFileSize=5MBlog4j.appender.Client.MaxBackupIndex=10log4j.appender.Client.layout=org.apache.log4j.PatternLayoutlog4j.appender.Client.layout.ConversionPattern=[%5p] %d [%X{userName}] [%X{remoteIp}] %m%n
client.log结果
[ INFO] 2016-09-20 20:38:04,794 [] [] 1234567890
可以设置日志文件大小
log4j输出模板
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。