1. Definitions
1. com.habanoz.logging. CombinedDailyAndRollingFileAppender
This appender combines functions of log4j DailyRollingFileAppender and RollingFileAppender.
Files are rotated according to max file parameter. If rolling date reaches, all indexed files are renamed to have date pattern.
Rolling Algorithm can be depicted as follows:
file.log (name of log file.corresponds to File param.)
if(maxFileSize) { (corresponds to MaxFileSize param.)
file.log -> file.log.1
file.log.1 -> file.log.2
..
file.log.max-1 -> file.log.max (max determined by MaxBackupIndex param)
}
if(date passed) { (determined by DatePattern param.)
file.log -> file.log.date
file.log.1 -> file.log.date.1
file.log.2 -> file.log.date.2
..
file.log.max-> file.log.date.max
}
Example log4j Configuration:
log4j.appender.defaultLog=com.habanoz.logging.CombinedDailyAndRollingFileAppender
log4j.appender.defaultLog.File=catchAll.1.log
log4j.appender.defaultLog.MaxFileSize=500MB
log4j.appender.defaultLog.MaxBackupIndex=20
log4j.appender.defaultLog.DatePattern=.yyyy-MM-dd
log4j.appender.defaultLog.layout=org.apache.log4j.PatternLayout
log4j.appender.defaultLog.layout.ConversionPattern=%d{${datestamp}} [%t] [%c] %-5p %m%n
2. com.habanoz.logging. CreationDateNamedRollingFileAppender
This appender is basically the same as RollingFileAppender. File is created with a name containing date string. If max file size is reached,
file is closed and a new file is created, having the same date pattern added to its name.
Logic can be depicted as follows:
file.date.log (file comes from File param.)
if(maxFile) { (maxFile comes from MaxFileSize param.)
close file.date.log
open new file.
}
Example log4j Configuration:
log4j.appender.defaultLog.2=com.habanoz.logging.CreationDateNamedRollingFileAppender
log4j.appender.defaultLog.2.File=catchAll.1.log
log4j.appender.defaultLog.2.MaxFileSize=500MB
log4j.appender.defaultLog.2.layout=org.apache.log4j.PatternLayout
log4j.appender.defaultLog.2.layout.ConversionPattern=%d{${datestamp}} [%t] [%c] %-5p %m%n
3. com.habanoz.logging. LastAccessDateNamedRollingFileAppender
This appender is basically the same as RollingFileAppender. Logic is changed to rename files with date pattern,
instead of rotating according to maxBackUpIndex.Log file is created. If max file size is reached it is closed and renamed with creation time.
Logic can be depicted as follows:
file.log (file comes from File param.)
if(maxFile) { (maxFile comes from MaxFileSize param.)
file.log -> file.YYYY-MM-dd HH-MM-ss.log (last-access time is used.)
open new file.
}
Example log4j Configuration:
log4j.appender.defaultLog.3=com.habanoz.logging.LastAccessDateNamedRollingFileAppender
log4j.appender.defaultLog.3.File=catchAll.3.log
log4j.appender.defaultLog.3.MaxFileSize=500MB
log4j.appender.defaultLog.3.layout=org.apache.log4j.PatternLayout
log4j.appender.defaultLog.3.layout.ConversionPattern=%d{${datestamp}} [%t] %-5p %m%n
2. Conclusion
Java files can be downloaded from this link.
Comments
Post a Comment