Logger配置檔案說明
檔案一定在src下,并命名為log4j.properties
### 全局預設配置
log4j.rootLogger = debug,stdout,D,E
### 設定控制台日志輸出 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
##設定日志級别
log4j.appender.stdout.Threshold = INFO
##布局樣式
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
##具體樣式格式
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
###設定檔案輸出配置###
##每天産生一個DEBUG日志檔案放到指定目錄=E://logs/error.log
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
##log4j.appender.D.File =logs/log.log
##輸出檔案位址
log4j.appender.D.File =E://logs/log.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} [ %t:%r ] - [ %p ] %m%n
### 每天産生一個ERROR級别日志到指定目錄存儲=E://logs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
詳解
https://blog.csdn.net/anlina_1984/article/details/5313023/