lundi 12 janvier 2015

Problems programmatically configuring log4j for daily and size rollover


Vote count:

0




Due to conflicts with other config files, I am trying to configure log4j programmatically to roll over log files daily, as well as by file size. The time portion seems to be working, but I can't get the log to roll over by size. This my my code:



RollingFileAppender appender = new RollingFileAppender();
appender.setName(PACKAGE_BASE + hoodName + "Reads.PackRat");
appender.setFile("Reads.log");

TimeBasedRollingPolicy timeBasedRollingPolicy = new TimeBasedRollingPolicy();
timeBasedRollingPolicy.setFileNamePattern("Reads-%d{yyyy-MM-dd}.log.gz");
SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy();
//8000 bytes
sizeBasedTriggeringPolicy.setMaxFileSize(8000);

appender.setRollingPolicy(timeBasedRollingPolicy);
appender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
appender.setLayout(new PatternLayout());
appender.activateOptions();
Logger logger = Logger.getLogger("SomeClass.class");
logger.addAppender(appender);


asked 50 secs ago







Problems programmatically configuring log4j for daily and size rollover

Aucun commentaire:

Enregistrer un commentaire