[logback-user] Setting the log file file size with RollingFileAdapter does not work
adriana lima
feminity2001 at yahoo.com
Wed Oct 30 11:57:29 CET 2013
Hello everyone,
I am trying to specify the size of my log file in my Java code. However, no file is written in the specified directory. Using a FileAppender without a triggering policy works fine. But I would like to specify the max. log file size. Any help is appreciated :) Thanx in advance!
Here is my code:
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
fileAppender.setContext(loggerContext);
fileAppender.setFile("C:\\log\\log.txt");
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
triggeringPolicy.setMaxFileSize("5MB");
triggeringPolicy.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%d %level %logger: %msg%n");
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.setTriggeringPolicy(triggeringPolicy);
fileAppender.start();
Logger logbackLogger = loggerContext.getLogger("ExportMapToFile");
((ch.qos.logback.classic.Logger) logbackLogger).addAppender(fileAppender);
logbackLogger.info(info);
fileAppender.stop();
triggeringPolicy.stop();
encoder.stop();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20131030/6ed42ea0/attachment.html>
More information about the Logback-user
mailing list