微信搜索superit|邀请体验:大数据, 数据管理、OLAP分析与可视化平台 | 赞助作者:赞助作者

log4j

java aide_941 19℃
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.19</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.19</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.17</version>
</dependency>

set log levels

log4j.rootLogger=debug,stdout,debug,error,rsyslog
#log4j.rootLogger=debug,debug,error,rsyslog

配置根Logger:设定日志记录的最低级别

log4j.category.org.springframework=ERROR
log4j.category.org.apache=INFO
log4j.logger.org.hibernate=ERROR

输出到控制台

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH:mm:ss}][%t] %l %m %n

输出到日志文件

log4j.appender.debug=org.apache.log4j.DailyRollingFileAppender
log4j.appender.debug.File = ${catalina.home}/msp-logs/info.log
log4j.appender.debug.datePattern=’.’yyyy-MM-dd
log4j.appender.debug.append=true
log4j.appender.debug.Threshold=DEBUG
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH:mm:ss}][%t] %l %m %n

ERROR输出到日志文件

log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File = ${catalina.home}/msp-logs/error.log
log4j.appender.error.datePattern=’.’yyyy-MM-dd
log4j.appender.error.append=true
log4j.appender.error.Threshold=ERROR
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH:mm:ss}] %l %m %n

#appender rsyslog 端口不可配置,使用默认的:514
log4j.appender.rsyslog=org.apache.log4j.net.SyslogAppender
log4j.appender.rsyslog.syslogHost=11.4.74.26
log4j.appender.rsyslog.Facility=local1
log4j.appender.rsyslog.FacilityPrinting=true
log4j.appender.rsyslog.header=true
log4j.appender.rsyslog.layout=org.apache.log4j.PatternLayout
log4j.appender.rsyslog.layout.conversionPattern=WEIXIN-MSP %d [%-5p] [%t] – %m%n

转载请注明:SuperIT » log4j

喜欢 (0)or分享 (0)