logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

RE: Can I have time stamp in log file name?: msg#00062

apache.logging.log4cxx.user

Subject: RE: Can I have time stamp in log file name?

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()));
 
        BasicConfigurator.resetConfiguration();
        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

Cheers,
Jess
 
-----Original Message-----
From: FabijanicA@xxxxxxxxxxxxxx [mailto:FabijanicA@xxxxxxxxxxxxxx]
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" <ambarish_mitra@xxxxxxxxxxxxxxxx> 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.
<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo