log4j常用日志配置

按照日志文件大小来切割日志文件配置:

# info
log4j.appender.infoLog=org.apache.log4j.RollingFileAppender
log4j.appender.infoLog.maxFileSize=2MB
log4j.appender.infoLog.maxBackupIndex=50
log4j.appender.infoLog.File=./logs/info.log
log4j.appender.infoLog.threshold=info
log4j.appender.infoLog.layout=org.apache.log4j.PatternLayout
log4j.appender.infoLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %l - %m%n

# error
log4j.appender.errorLog=org.apache.log4j.RollingFileAppender
log4j.appender.errorLog.maxFileSize=2MB
log4j.appender.errorLog.maxBackupIndex=50
log4j.appender.errorLog.File=./logs/error.log
log4j.appender.errorLog.threshold=error
log4j.appender.errorLog.layout=org.apache.log4j.PatternLayout
log4j.appender.errorLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %l - %m%n

# stdout
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=%-d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %l - %m%n

# rootLogger
log4j.rootLogger=info, stdout, infoLog, errorLog

按照日期来切割日志文件配置:

# info
log4j.appender.infoLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.infoLog.DatePattern=''.''yyyy-MM-dd
log4j.appender.infoLog.File=./logs/info.log
log4j.appender.infoLog.Threshold=info
log4j.appender.infoLog.layout=org.apache.log4j.PatternLayout
log4j.appender.infoLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %l - %m%n

# error
log4j.appender.errorLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.errorLog.DatePattern=''.''yyyy-MM-dd
log4j.appender.errorLog.File=./logs/error.log
log4j.appender.errorLog.Threshold=error
log4j.appender.errorLog.layout=org.apache.log4j.PatternLayout
log4j.appender.errorLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %l - %m%n

# stdout
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=%-d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %l - %m%n

# rootLogger
log4j.rootLogger=info, stdout, infoLog, errorLog

你可能感兴趣的:(log4j常用日志配置)