logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jess.Morecr...@ubs.com
Subject RE: Can I have time stamp in log file name?
Date Mon, 21 Feb 2005 17:18:27 GMT
I had a similiar requirement at my work. We got around it by using the config system property
value substitution mechanism. It's not the best solution I'm sure, for many reasons, but it
worked for us.
To give an example, the first time you configure and everytime thereafter you want to change
the filename, you have code to do as follows:
        Date now = new Date();
        System.setProperty("log4j.hours", new String(now.getHours()));
        System.setProperty("log4j.minutes", new String(now.getMinutes()));
        System.setProperty("log4j.seconds", new String(now.getSeconds()));

The contents of your log4j.properties file then looks something like this:
        log4j.rootLogger=INFO, A1
        log4j.appender.A1.layout.ConversionPattern=%p %t %c - %m%n


-----Original Message-----
From: FabijanicA@nucorsteel.com [mailto:FabijanicA@nucorsteel.com]
Sent: 21 February 2005 13:39
To: Log4CXX User
Subject: Re: Can I have time stamp in log file name?

AFAICT, the closest to what you are looking for would be the DailyRolingFileAppender - it
automatically renames old example.log to example.log.date format at midnight, when the new
day file is created. 

But, then there are few (significant) catches - there is no option to automatically delete
old files (really a pain). Also, it has been deprecated in log4j (in favor of using strategy
design pattern, I believe), so I guess it will go away in log4cxx as well. 


"Ambarish Mitra" <ambarish_mitra@persistent.co.in> wrote on 02/21/2005 08:07:49 AM:

> Hi,
> Can I have time stamp in log file name?
> To elaborate, if my entries in the property files are:
> ...
> log4j.appender.R=org.apache.log4j.RollingFileAppender
> log4j.appender.R.File=../logs/example.log
> ..
> Now, I want that instead of log file name: example.log, I want the name as
> example.log.<time> of creation, is there any way to accomplish this?
> -Ambarish.
> [attachment "winmail.dat" deleted by Aleksandar Fabijanic/Maintenance/NSB] 

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.

View raw message