eabrand
eabrand

Reputation: 226

Log4j FileNamePattern in DailyRollingFileAppender

Is there a way to specify a pattern for an original filename?

I essentially want to do the following:

<param name="file" value="%d{yyyy/MM/dd HH:mm:ss}: %m%n_testlog.log"/>

How would I go about doing this?

Upvotes: 1

Views: 5371

Answers (2)

Paul
Paul

Reputation: 20061

I have a daily rolling log but I do it a little differently, using TimeBasedRollingPolicy from log4j extras:

<log4j:configuration debug="true">
  <appender name="roll" class="org.apache.log4j.rolling.RollingFileAppender">
    <param name="append" value="true" />
    <param name="encoding" value="UTF-8" />
    <!-- The active file to log to -->
    <param name="file" value="/location/to/log/current.log />
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
      <param name="FileNamePattern" 
             value="/location/to/log/archive/oldLog-%d{yyyy-MM-dd}.log" />
    </rollingPolicy>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{DATE} %5p %c{2} - %m%n" />
    </layout>
  </appender>
  <logger name="mypackage">
    <level value="debug" />
    <appender-ref ref="roll" />
  </logger>
</log4j:configuration>

The above is in my code, which I based on this entry at the log4j Wiki.

Paul

Upvotes: 1

Hong Ning
Hong Ning

Reputation: 1003

I'm not sure this would help you:

<param name="File" value="Info"/> 
<param name="DatePattern" value="yyyy-MM-dd-HH-mm-ss'_testlog.log'"/>

Upvotes: 0

Related Questions