Log4j is a cool Java library which helps inserting log entry in the code. One of the best features of this logging library is the usage of the DailyRollingFileAppender for archive purposes. This appender allows you to roll the files with the user choosen frequency.
The configuration is quite simple, according to the manual:
# Default Log - Catch all
log4j.rootLogger=DEBUG, stdout, logfile
# Console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c.%M:%L] - <%m>%n
# File
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=${log.dir}/${log.apptype}/log.log
log4j.appender.logfile.DatePattern=.yyyy-MM-dd
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
By following this approach, each log file will be archived like log.log.2009-01-01.log, log.log.2009-01-02.log.
No comments:
Post a Comment