Wednesday, April 25, 2012

log4j.properties

Following is a sample log4j.properties, which output all logs to console and writes INFO+ level log to a file
#default log level is set to 'debug' it will output all log to console 
log4j.rootLogger=debug,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %5p %c{1}:%L - %m%n

#log level that is >=INFO, will use defaultLog definition for packagename
log4j.category.packagename=INFO, defaultLog

#define the log file directory
log.dir=/some/directory/logname.log

datestamp=yyyy-MM-dd/HH:mm:ss.SSS/zzz
roll.pattern.daily=.yyyy-MM-dd

#defines defaultLog, log file is rotated daily
log4j.appender.defaultLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.defaultLog.DatePattern=${roll.pattern.daily}
log4j.appender.defaultLog.File=${log.dir}
log4j.appender.defaultLog.layout=org.apache.log4j.PatternLayout
log4j.appender.defaultLog.layout.ConversionPattern=%d{${datestamp}} [%t] %-5p %m%n

No comments:

Post a Comment