public Logger logger = Logger.getLogger(Test.class);
打印堆栈信息
org.apache.logging.log4j.Logger.error(String message, Throwable t)
log4j.properties配置文件
以下为配置内容:
log4j.rootLogger=INFO, stdout, RollingFile
# Console Appender
log4j.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,SSS} [%t] %-5p %c %x - %m%n
# Custom tweaks
log4j.logger.com.codahale.metrics=WARN
log4j.logger.com.ryantenney=WARN
log4j.logger.com.zaxxer=WARN
log4j.logger.org.apache=WARN
log4j.logger.org.hibernate=WARN
log4j.logger.org.hibernate.engine.internal=WARN
log4j.logger.org.hibernate.validator=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.springframework.web=WARN
log4j.logger.org.springframework.security=WARN
# log file
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = D:/ytzz/yulin/materialized/log/test.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%p] [%l] - %m%n
#RollingFile 按大小生成日志
log4j.appender.RollingFile = org.apache.log4j.RollingFileAppender
#log4j.appender.RollingFile.File = D:/ytzz/yulin/materialized/log/log4j_materialized.log
#vm启动参数 自定义 -Dlog4jOutputPath=./log/log4j_materialized.log
log4j.appender.RollingFile.File = ${log4jOutputPath}
log4j.appender.RollingFile.MaxFileSize=102400kb
log4j.appender.RollingFile.MaxBackupIndex=50
log4j.appender.RollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%p] [%l] - %m%n