Discussion:
Adding the date as part of the file name.
Anthony Smith
2005-05-31 13:12:17 UTC
Permalink
I want my log file to ed with the current date which means it will start
a new log file each day...

Well actually is there is more than one file because of my max file size
I want it to end with the backup index.



Right now it just creates the files as prerating.log.1, prerating.log.2,
and so on...



I don't know how to add the date as part of the file name. I thought
this line did that:

log4j.appender.PRERATING.DatePattern='.'yyyy-MM-dd







log4j.appender.PRERATING=org.apache.log4j.RollingFileAppender

log4j.appender.PRERATING.MaxFileSize=1MB

log4j.appender.PRERATING.MaxBackupIndex=10

log4j.appender.PRERATING.DatePattern='.'yyyy-MM-dd

log4j.appender.PRERATING.File=${log.dir}/prerating.log

log4j.appender.PRERATING.layout=org.apache.log4j.PatternLayout

log4j.appender.PRERATING.layout.ConversionPattern=%d{ISO8601} %p - %m%n

log4j.logger.intltech.autopay.servlets.PreRateRatingServlet=INFO,
PRERATING

log4j.logger.intltech.autopay.beans=INFO, PRERATING
OOMS DIRK
2005-05-31 13:19:49 UTC
Permalink
the below xml configuration works for me

<appender name="PatternFileAppender"
class="org.apache.log4j.rolling.RollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern"
value="/home/dirk/jakarta-tomcat-5.5.9/logs/myApp.log.%d{yyyy-MM-dd}.gz"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}, %p,
%c{1}] %m%n"/>
</layout>
</appender>
-----Original Message-----
Sent: dinsdag 31 mei 2005 15:12
To: Log4J Users List
Subject: Adding the date as part of the file name.
I want my log file to ed with the current date which means it
will start
a new log file each day...
Well actually is there is more than one file because of my
max file size
I want it to end with the backup index.
Right now it just creates the files as prerating.log.1,
prerating.log.2,
and so on...
I don't know how to add the date as part of the file name. I thought
log4j.appender.PRERATING.DatePattern='.'yyyy-MM-dd
log4j.appender.PRERATING=org.apache.log4j.RollingFileAppender
log4j.appender.PRERATING.MaxFileSize=1MB
log4j.appender.PRERATING.MaxBackupIndex=10
log4j.appender.PRERATING.DatePattern='.'yyyy-MM-dd
log4j.appender.PRERATING.File=${log.dir}/prerating.log
log4j.appender.PRERATING.layout=org.apache.log4j.PatternLayout
log4j.appender.PRERATING.layout.ConversionPattern=%d{ISO8601}
%p - %m%n
log4j.logger.intltech.autopay.servlets.PreRateRatingServlet=INFO,
PRERATING
log4j.logger.intltech.autopay.beans=INFO, PRERATING
Curt Arnold
2005-05-31 15:29:46 UTC
Permalink
The configuration fragment assumes log4j 1.3.

log4j 1.2 had two rolling file appenders
org.apache.log4j.RollingFileAppender which rolled on the next event
after a file size limit was reached and
org.apache.log4j.DailyRollingFileAppender which rolled on the next
event after a date change. log4j 1.3 introduced a new framework
which allowed user provided triggering policies (what to roll on) and
rolling policies (how to name or rename files on a rollover). The
old org.apache.log4j.RollingFileAppender and
o.a.l.DailyRollingFileAppender are emulated using the new framework.

Log4j 1.3 would allow the flexibility to create a hybrid where both
size and time were used as rolling criteria, but there is no such
implementation at this time.

The max backup limit issue does not apply to time based rolling files
since the rolled files do not need to be renamed. In the
org.apache.log4j.RollingFileAppender, each rollover requires MyLog.0
to be renamed to MyLog.1, ... My Log.n-1 to MyLog.n so a large limit
could result in a substantial amount of time being involved in
renaming files.

If you are limited to log4j 1.2.x, use
org.apache.log4j.DailyRollingFileAppender. If you are using log4j
1.3.x, use a fragment like the one provided. If daily rolling is not
sufficient, you can extend the filename format to rollover more
frequently.
Post by OOMS DIRK
the below xml configuration works for me
<appender name="PatternFileAppender"
class="org.apache.log4j.rolling.RollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<rollingPolicy
class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern"
value="/home/dirk/jakarta-tomcat-5.5.9/logs/myApp.log.%d{yyyy-MM-
dd}.gz"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd
HH:mm:ss}, %p,
%c{1}] %m%n"/>
</layout>
</appender>
Loading...