I need to create a new log file everyday, an old file has to be renamed with pattern: "test.yyy-MM-dd.log". And files older than 7 days have to be removed. Below is my .properties file. Can someone explain what I have to add/change pls?
log4j.rootLogger=DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
# Set the name of the file
log4j.appender.FILE.File=logs/test.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.Append=true
log4j.appender.FILE.MaxFileSize=5MB
log4j.appender.MaxBackupIndex=10
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%C]: %m%n
According to official log4j docs
means
So first step is accomplished.
The
menas
You want 7, but configured 10
Next
So each file can be max 5MB, if you will produce 7mb of logs in one day then two different files will be created.
Have you tested that config? Does it work? What works as expected and what doesn't? Have you read any documentation or tutrial?