Log4j.properties基本配置

Log4j.properties基本配置:

log4j.rootLogger = DEBUG, CONSOLE, FILE, ROLLING_FILE

log4j.logger.java.sql.Connection = DEBUG
log4j.logger.java.sql.PreparedStatement = DEBUG
log4j.logger.java.sql.Statement = DEBUG
log4j.logger.java.sql.ResultSet = DEBUG

# 应用于控制台
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold = DEBUG
# 默认值是true,意谓着所有的消息都会被立即输出。
#log4j.appender.CONSOLE.ImmediateFlush = true
log4j.appender.CONSOLE.Target = System.out
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %5p [%13F:%L] - %m%n

# 应用于文件
log4j.appender.FILE = org.apache.log4j.FileAppender
log4j.appender.FILE.Threshold = INFO
# log4j.appender.FILE.ImmediateFlush = true
# 默认值是true,即将消息增加到指定文件中,false指将消息覆盖指定的文件内容。
# log4j.appender.FILE.Append = true
log4j.appender.FILE.File = logs/info.log
log4j.appender.FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %5p [%13F:%L] - %m%n 

# 应用于事物回滚
log4j.appender.ROLLING_FILE = org.apache.log4j.RollingFileAppender
log4j.appender.ROLLING_FILE.Threshold = WARN
# log4j.appender.ROLLING_FILE.ImmediateFlush = true
# log4j.appender.ROLLING_FILE.Append = true
log4j.appender.ROLLING_FILE.File = logs/rolling.log
log4j.appender.ROLLING_FILE.MaxFileSize = 10M
log4j.appender.ROLLING_FILE.MaxBackupIndex = 10
log4j.appender.ROLLING_FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %5p [%13F:%L] - %m%n

# org.apache.log4j.DailyRollingFileAppender
#log4j.appender.ROLLING_FILE = org.apache.log4j.org.apache.log4j.DailyRollingFileAppender
#log4j.appender.ROLLING_FILE.Threshold = WARN
#log4j.appender.ROLLING_FILE.File = logs/rolling.log
#log4j.appender.ROLLING_FILE.layout = org.apache.log4j.PatternLayout
#log4j.appender.ROLLING_FILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %5p [%13F:%L] - %m%n

PS:关于具体的详解可以参考其他的博客说明,特别是文件输出路径的配置。

在上面的代码中log日志你可以在服务器tomcat的bin目录下找到。

相关推荐