1 #set log levels:ALL,TRACE, DEBUG, INFO, WARN, ERROR ,FATAL,OFF
2 log4j.rootLogger = INFO, stdout, file
3 #console
4 log4j.appender.stdout = org.apache.log4j.ConsoleAppender
5 log4j.appender.stdout.Target = System.out
6 log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
7 log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss SSS} %-5p %c{1}:%L - %m%n
8 # overwirte the old log file
9 log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
10 log4j.appender.file.File = ./logs/testlog.log
11 log4j.appender.file.Append = true
12 log4j.appender.file.Threshold = INFO
13 log4j.appender.file.layout = org.apache.log4j.PatternLayout
14 log4j.appender.file.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss SSS} %-5p %c{1}:%L - %m%n
1 log4j.appender.file.Threshold=warn 配置的级别是输出到文件中的级别
2 log4j.rootLogger=info,console,file 其中的info是输出到控制台的级别
3 log4j.appender.file.Append = true true表示消息增加到指定文件中,false则将消息覆盖指定的文件内容
原文:https://www.cnblogs.com/cty136/p/11546025.html