My log needs to have maxsize 5KB, no backup files and needs to append. When the log reach 5KB it erase the amount of data necessary to fit the new data. For example:
1: a b c d
2: b c d e
3: c d e f
Logger rootLogger = Logger.getRootLogger();
rootLogger.setLevel(Level.DEBUG);
PatternLayout layout = new PatternLayout("%d{ISO8601} [%t] %-5p %c %x - %m%n");
rootLogger.addAppender(new ConsoleAppender(layout));
RollingFileAppender fileAppender = new RollingFileAppender(layout, "test.log");
fileAppender.setAppend(true);
fileAppender.setMaxFileSize("5KB");
fileAppender.setMaxBackupIndex(0);
My problem is when the size reach 5KB. It doesn't append (roll) like I want, its overwrite the hole data. Why it doesn't append? Can anyone help me?
I think you misunderstand how the RollingFileAppender works. Javadoc: RollingFileAppender extends FileAppender to backup the log files when they reach a certain size.
So it rolls over a number of files and not the lines/content in one file.
kind regards, soilworker