Hi,
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()));
System.setProperty("log4j.hours", new String(now.getHours()));
System.setProperty("log4j.minutes", new String(now.getMinutes()));
System.setProperty("log4j.seconds", new String(now.getSeconds()));
BasicConfigurator.resetConfiguration();
PropertyConfigurator.configure("log4j.properties");
PropertyConfigurator.configure("log4j.properties");
The
contents of your log4j.properties file then looks something like
this:
log4j.rootLogger=INFO,
A1
.
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=/home/log/Log_${log4j.hours}_${log4j.minutes}_${log4j.seconds}.txt
log4j.appender.A1.MaxFileSize=100KB
log4j.appender.A1.MaxBackupIndex=1
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=/home/log/Log_${log4j.hours}_${log4j.minutes}_${log4j.seconds}.txt
log4j.appender.A1.MaxFileSize=100KB
log4j.appender.A1.MaxBackupIndex=1
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%p %t %c - %m%n
Cheers,
Jess
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
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.
Alex
"Ambarish Mitra" <[EMAIL PROTECTED]> 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.
