2

My stdout single log file is growing over 5gb every week. It's too big and can't be opened with normal text editor like notepad++. Is there any way to:

  1. Limit file size around 100mb. If it reaches 100mb, then create a new file
  2. Limit the number of log files around 5. If the 6th stdout is created, then the oldest file will be deleted automatically.

In log4j.properties, I have the following:

#------------------- CONSOLE --------------------------
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender

log4j.appender.CONSOLE.threshold=INFO

log4j.appender.CONSOLE.target=System.out

log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p [%t] %c{1} %m %n

I know we can do it with "RollingFileAppender", set MaxFileSize=100mb and set MaxBackupIndex=5. But for "ConsoleAppender", is there anyway to achieve the same?

tn_
  • 21
  • 2
  • Check out http://stackoverflow.com/questions/1200175/log4j-redirect-stdout-to-dailyrollingfileappender – ug_ Jul 08 '16 at 16:56
  • @ug_: I am under impression that we cannot use ConsoleAppender with RollingFileAppender or DailyFIleAppender in the same "block". A "block" I mean here is whatever you define between log4j.appender.CONSOLE=org.apache.log4j.type1 (i.e. ConsoleAppender) and log4j.appender.CONSOLE=org.apache.log4j.type2 (i.e. FileAppender) Am I right? – tn_ Jul 08 '16 at 18:04

0 Answers0