log4j每天 每小时 每分钟生成多个日志文件

1 生成多个日志文件
每天生成一个日志文件的log4j.properties配置为

log4j.rootLogger=INFO,console,file
# ALL TRACE DEBUG INFO WARE ERROR FATAL OFF
#INFO DEBUG ERROR
#log4j.rootCategory=INFO, stdout, R

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#windows
#log4j.appender.file.File=E:/cdcMonitorWAS.log
#linux
log4j.appender.file.File=/cdcMonitorWAS/logs/cdcMonitorWAS.log
log4j.appender.file.DatePattern=yyyy-MM-dd'.txt'

#SqlMap logging configuration...
#log4j.logger.com.ibatis=DEBUG
#log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
#log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
#log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
#log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
#log4j.logger.java.sql.ResultSet=DEBUG

log4j.appender.console.layout=org.apache.log4j.SimpleLayout
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %-5p %20c %3x - %m%n
#log4j.appender.file.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %-10r %-5p [%t] %20c %3x - %m%n

log4j.logger.com.ibatis=debug 
log4j.logger.com.opensymphony.xwork2=info 
log4j.logger.java.sql=debug 
log4j.logger.org.apache.struts=info 
log4j.logger.org.springframework=info 
log4j.logger.org.apache.cxf=info 

生成多个日志文件文件需要在log4j.properties添加配置

log4j.rootLogger=INFO,console,file,file2
# ALL TRACE DEBUG INFO WARE ERROR FATAL OFF
#INFO DEBUG ERROR
#log4j.rootCategory=INFO, stdout, R

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#windows
#log4j.appender.file.File=E:/cdcMonitorWAS.log
#linux
log4j.appender.file.File=/cdcMonitorWAS/logs/cdcMonitorWAS.log
log4j.appender.file.DatePattern=yyyy-MM-dd'.txt'


#file2----------
log4j.appender.file2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file2.Append=true
log4j.appender.file2.DatePattern=yyyy-MM-dd'.txt'
log4j.appender.file2.File=/cdcMonitorWAS/logs/cdcMonitorWASfileSetupHH.log
log4j.appender.file2.Threshold=INFO
log4j.appender.file2.Encoding=UTF-8
log4j.appender.file2.layout=org.apache.log4j.PatternLayout
log4j.appender.file2.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %-5p %20c %3x - %m%n


#SqlMap logging configuration...
#log4j.logger.com.ibatis=DEBUG
#log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
#log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
#log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
#log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
#log4j.logger.java.sql.ResultSet=DEBUG

log4j.appender.console.layout=org.apache.log4j.SimpleLayout
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %-5p %20c %3x - %m%n
#log4j.appender.file.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %-10r %-5p [%t] %20c %3x - %m%n

log4j.logger.com.ibatis=debug 
log4j.logger.com.opensymphony.xwork2=info 
log4j.logger.java.sql=debug 
log4j.logger.org.apache.struts=info 
log4j.logger.org.springframework=info 
log4j.logger.org.apache.cxf=info 

这样就会在/cdcMonitorWAS/logs/路径下生成cdcMonitorWASfileSetupHH.log日志文件
2 每小时或每分钟生成日志文件
控制生成时间的配置为

log4j.appender.file2.DatePattern=yyyy-MM-dd'.txt'

每小时生成日志文件,修改为

log4j.appender.file2.DatePattern=yyyy-MM-dd-HH'.txt'

每分钟生成日志文件,修改为

log4j.appender.file2.DatePattern=yyyy-MM-dd-HH-mm'.txt'

你可能感兴趣的:(日志)