Pawan
Pawan

Reputation: 32321

Log4j: DailyRollingFileAppender with 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 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.

Upvotes: 9

Views: 26018

Answers (3)

Srikar
Srikar

Reputation: 129

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

Upvotes: 5

Erdinc Ay
Erdinc Ay

Reputation: 3273

Use the RollingFileAppender, you are using the wrong Appender!

Upvotes: 1

nayakam
nayakam

Reputation: 4239

You could extend the FileAppender class and implement your custom version. More details DailyRollingFileAppender

Upvotes: 7

Related Questions