[logback-user] Adding a timestamp to a FileAppender file

Ceki Gulcu listid at qos.ch
Thu Oct 30 15:42:37 CET 2008


A jira issue sounds good. Given that the RollingFileAppender already
inherits from FileAppender and is getting pretty complicated to
maintain, I would prefer a new class, e.g. ExtFileAppender. At the
same time, since the idea of a resolver also makes sense in
RollingFileAppender, FileAppender might still be the right place.

It's a case of definitely, maybe.

Ralph Goers wrote:
> I would suggest you create a Jira issue for this. I would suggest the 
> ability to add a custom pattern resolver to the appender might be what 
> you want. Before Logback I had written my own logging framework that 
> supported this. I had considered making this request myself but so far I 
> am not sure that we actually need it yet.  It could look something like:
> 
> <appender name="file" class="ch.qos.logback.core.FileAppender">
>   <File 
> resolver="com.mycorp.logback.MyPatternResolver">myjob.%{host}.%{datetime}.log</File>
>   <Append>false</Append>
>   <layout class="ch.qos.logback.classic.PatternLayout">
>     <Pattern>%msg%n</Pattern>
>   </layout>
> </appender>
> 
> The Resolver interface would have a single method that looks like   
> String resolve(String pattern)
> 
> Ralph
> 
> nicolas.giraud at bnf.fr wrote:
>> Thanks for the answer, Hannes.
>>
>> However a time-based rollover is not what I am looking for. My program 
>> executes one job at a time. There are several jobs  whose duration 
>> varies from a couple of seconds to several hours.  I simply want to 
>> log the results of a job in a single file, and have the filename 
>> contain a timestamp.
>>
>> I will have to do this programmatically obviously, but I'm having 
>> trouble setting up the file appender programmatically.
>>
>> Regards,
>> Nicolas
>>
>>
>> *Avant d'imprimer, pensez à l'environnement.*
>> Consider the environment before printing this mail.
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://qos.ch/mailman/listinfo/logback-user
>>   
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch


More information about the Logback-user mailing list