Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FileNamePattern, RollingFileAppender in log4j

I have a log file named app.log. When it rolls over (I'm setting it to every minute just for testing purposes), I would like it to be renamed to app-YYYY-MM-dd_HH-mm.log but it's not working. Below is my log4j settings:

log4j.appender.myLog=org.apache.log4j.RollingFileAppender
log4j.appender.myLog.rollingPolicy=TimeBasedRollingPolicy
log4j.appender.myLog.File=logs/app.log
log4j.appender.myLog.rollingPolicy.FileNamePattern=logs/app-%d{yyyy-MM-dd_HH-mm}.log
log4j.appender.myLog.Append=true
log4j.appender.myLog.layout=org.apache.log4j.PatternLayout
log4j.appender.myLog.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n

Does anyone know what's the problem? During the rollover, it just renames the file into app.log.1.

like image 528
jasonline Avatar asked Dec 01 '10 12:12

jasonline


1 Answers

According to the log4j wiki:

Note that TimeBasedRollingPolicy can only be configured with xml, not log4j.properties

The API doesn't mention that, but perhaps that's the problem?

like image 165
Paul Avatar answered Sep 17 '22 16:09

Paul