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 Order , so I am using DailyRollingFileAppender
.
But the issue is that this log file currently cannot hold much data (meaning when lot of requests are made on that day) it looses the previous log data
I tried to use the option MaxFileSize
:
log4j.appender.A1.MaxFileSize=10MB
But on to the server console its giving error that property MaxFileSize
isn't supported .
Please tell me if there is any other way that the log appears date wise and it can hold as much data as specified.
maxFileSize. The default maximum file size is 10MB. Fields inherited from class org.apache.log4j.FileAppender.
Log4j2 RollingFileAppender is an OutputStreamAppender that writes log messages to files, following a configured triggering policy about when a rollover (backup) should occur. It also has a configured rollover strategy about how to rollover the file.
maxBackupIndex This property denotes the number of backup files to be created. Default value is 1. Following is a sample configuration file log4j. properties for RollingFileAppender. # Define the root logger with appender file.
You could extend the FileAppender class and implement your custom version. More details DailyRollingFileAppender
You could use DailyRollingFileAppender
with the hourly backup option. This will rollover the logs every hour.
Hourly Usage:
log4j.appender.A1.datePattern='.'yyyy-MM-dd-HH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With