2

In my application I use the library log4j to generate logs of the entire system. Is working correctly, use the following settings:

Direct log messages to a log file:

log4j.appender.file = org.apache.log4j.DailyRollingFileAppender 
log4j.appender.file.File = log / aplicacao.log 
log4j.appender.file.DatePattern = '.' yyyy-MM-dd 
log4j.appender.file.layout = org.apache.log4j.PatternLayout 
log4j.appender.file.layout.ConversionPattern =% d {MM-dd-yyyy, HH: mm: ss: SSS},% t,%-5p,% c {1}:% L-% m% n 
log4j.appender.file.MaxFileSize = 50KB 
log4j.appender.file.MaxHistory = 2 

I wonder if there is some property that makes clear old files that already have more than a week, because if my system remain running for a long time is not feasible to occupy a lot of memory because the application that I developed is to be used on machines very old.

Is there any solution for this? Maxfilesize and MaxHistory added the property and it does not work.

Philipp Sander
  • 10,139
  • 6
  • 45
  • 78
fymoribe
  • 199
  • 1
  • 11

1 Answers1

1

MaxHistory would do what you want but only if you use a numeric file pattern (file, file.0, file.1, ..., file.N). It doesn't work for date based file patterns.

If you don't want to give up date patterns in the log file name, then your next choice is a cron job that searches for old log files and deletes them. All OSs support this one way or the other.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820