Log4j: DailyRollingFileAppender with the MaxFileSize option

I am using this log4j.properties

log4j.rootCategory=Info, A1 # A1 is a DailyRollingFileAppender log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender log4j.appender.A1.file=D:/MyWeb.log log4j.appender.A1.datePattern='.'yyyy-MM-dd log4j.appender.A1.append=true log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} - %m%n 

I want to display logs in the Date Wise method, so I use DailyRollingFileAppender . But the problem is that this log file cannot currently store a lot of data (which means that a lot of requests are being executed on this day), it loses the previous log data

I tried using the MaxFileSize option:

 log4j.appender.A1.MaxFileSize=10MB 

But on the server console, its error is that the MaxFileSize property is not supported.

Please tell me if there is another way for the log to look like a date and it can store as much data as possible.

+6
source share
3 answers

You can extend the FileAppender class and implement your own version. Read more DailyRollingFileAppender

+4
source

You can use the DailyRollingFileAppender with hourly backup capability. This will tip the magazines every hour.

Hourly use

log4j.appender.A1.datePattern = '' YYYY-MM-dd-nn

+4
source

Use RollingFileAppender , you are using the wrong Appender!

+1
source

Source: https://habr.com/ru/post/904161/


All Articles