[logback-user] Adding a timestamp to a FileAppender file
Lang, Johannes
Johannes.Lang at ipi.ch
Thu Oct 30 11:21:39 CET 2008
Hi Nicolas,
as far as i understand your goal, a RollingFileAppender would do the job.
The following appender is an example of a RollingFileAppender, which does
a Rollover every hour with de defined name-pattern. The rollover-policy is
defined by the time-pattern:
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>logFile.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>logFile.%d{yyyy-MM-dd_HH}.log</FileNamePattern>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
cheers
Hannes
________________________________
Von: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] Im Auftrag von nicolas.giraud at bnf.fr
Gesendet: Donnerstag, 30. Oktober 2008 11:09
An: logback-user at qos.ch
Betreff: [logback-user] Adding a timestamp to a FileAppender file
Hi,
I have just switched from log4j to logback. I would like to generate log containing results output by my program, and I want the file name to be SomePrefix.<timestamp>.someExt. I can do this programmatically but I'd like, if possible, to have all my logging configuration in my logback.xml file. Here's the appender I declared :
<appender name="resultFile" class="ch.qos.logback.core.FileAppender">
<file>${logFolder}/SomePrefix.%d.someExt</file>
<append>false</append>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
</filter>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%m%n</pattern>
</layout>
</appender>
However the %d pattern is not interpreted, is there a way to do this? Maybe using a RollingFileAppender, but I don't see how.
Regards,
Nicolas
Avant d'imprimer, pensez à l'environnement.
Consider the environment before printing this mail.
More information about the Logback-user
mailing list