You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Hjelmstad <je...@mdnt.com> on 2007/04/20 17:59:05 UTC

Time stamp in file name

Is there a way that I can add a timestamp to the file name that is not just a
rolling appender? 
I may start up and stop my software 10 or more times during the course of a
day and between those I have to remane the log file created manually. 
Does any one know of a way to automatically add a timestamp to the file name
at the start of the software initialization?
-- 
View this message in context: http://www.nabble.com/Time-stamp-in-file-name-tf3619129.html#a10105185
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Time stamp in file name

Posted by Hjelmstad <je...@mdnt.com>.
Thanks for the pointer.


Kamal Ahmed-3 wrote:
> 
> You can also use:
> 
> Timestamp File Appender
> 
> Appender creates a new log file on each start of an application, with
> the additional feature that the log file name contains the current
> timestamp.
> 
> Appender is pretty simple, it is derived from FileAppender and replaces
> string {timestamp} from the value of File property with the current
> timestamp.
> 
> Timestamp pattern is user configured by TimestampPattern property that
> has the same choice of formats as java.text.SimpleDateFormat
> 
> So, the solution is very flexible.
> 
> Here are the source code and configuration example file:
> 
> TimestampFileAppender.java timestampFileAppender.configuration
> 
> Located @
> http://wiki.apache.org/logging-log4j/UsefulCode
> 
> -Kamal.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Time-stamp-in-file-name-tf3619129.html#a10162408
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Time stamp in file name

Posted by Kamal Ahmed <KA...@webMethods.com>.
You can also use:

Timestamp File Appender

Appender creates a new log file on each start of an application, with
the additional feature that the log file name contains the current
timestamp.

Appender is pretty simple, it is derived from FileAppender and replaces
string {timestamp} from the value of File property with the current
timestamp.

Timestamp pattern is user configured by TimestampPattern property that
has the same choice of formats as java.text.SimpleDateFormat

So, the solution is very flexible.

Here are the source code and configuration example file:

TimestampFileAppender.java timestampFileAppender.configuration

Located @
http://wiki.apache.org/logging-log4j/UsefulCode

-Kamal.

-----Original Message-----
From: Hjelmstad [mailto:jeff.a.hjelmstad@mdnt.com] 
Sent: Monday, April 23, 2007 2:08 PM
To: log4j-user@logging.apache.org
Subject: Re: Time stamp in file name


Thanks for the help.


James Stauffer wrote:
> 
> My DateFormatFileAppender always includes the data pattern in the
> filename.
> http://stauffer.james.googlepages.com/DateFormatFileAppender.java
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Time-stamp-in-file-name-tf3619129.html#a10145856
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Time stamp in file name

Posted by Hjelmstad <je...@mdnt.com>.
Thanks for the help.


James Stauffer wrote:
> 
> My DateFormatFileAppender always includes the data pattern in the
> filename.
> http://stauffer.james.googlepages.com/DateFormatFileAppender.java
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Time-stamp-in-file-name-tf3619129.html#a10145856
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Logger name in the log entry

Posted by "Cheung, Quinn" <QC...@rheinmetall.ca>.
Oh yes, I see now. My mistake...



-----Original Message-----
From: dirk ooms [mailto:dirk@onesparrow.com]
Sent: April 23, 2007 4:40 PM
To: Log4J Users List
Subject: Re: Logger name in the log entry


On Monday 23 April 2007 22:16, Cheung, Quinn wrote:
> I'm afraid that doesn't work.  As I mentioned in the original mail, I don't
> want the class name.  I want the name (identifier) of the logger. In my
> case I'm not using the class name in the call to Logger.getLogger(),
> therefore the name of the logger is not the same as the class name.

as Jake said %c will display the name of the logger (category), which is not 
the name of the class (=%C)

>
>
>
>
> -----Original Message-----
> From: James Stauffer [mailto:stauffer.james@gmail.com]
> Sent: April 20, 2007 4:23 PM
> To: Log4J Users List
> Subject: Re: Logger name in the log entry
>
>
> c: Used to output the category of the logging event.
> C: Used to output the fully qualified class name of the caller issuing
> the logging request.
>
> On 4/20/07, Cheung, Quinn <QC...@rheinmetall.ca> wrote:
> > Using the PatternLayout and ConversionPattern, is there any way to
> > automatically print out the name of the logger that was used to log a
> > message?  I know I can get the name of the class which will coincide with
> > the logger name if I do:
> >
> > Logger theLogger = getLogger( TheClassName.class );
> >
> > But I'm not doing that, I'm doing:
> >
> > Logger theLogger = getLogger( "HardCodedString" );
> >
> > and I want "HardCodedString" to appear each time theLogger logs a
> > message.
> >
> > Thanks!
> >
> > Q.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Logger name in the log entry

Posted by dirk ooms <di...@onesparrow.com>.
On Monday 23 April 2007 22:16, Cheung, Quinn wrote:
> I'm afraid that doesn't work.  As I mentioned in the original mail, I don't
> want the class name.  I want the name (identifier) of the logger. In my
> case I'm not using the class name in the call to Logger.getLogger(),
> therefore the name of the logger is not the same as the class name.

as Jake said %c will display the name of the logger (category), which is not 
the name of the class (=%C)

>
>
>
>
> -----Original Message-----
> From: James Stauffer [mailto:stauffer.james@gmail.com]
> Sent: April 20, 2007 4:23 PM
> To: Log4J Users List
> Subject: Re: Logger name in the log entry
>
>
> c: Used to output the category of the logging event.
> C: Used to output the fully qualified class name of the caller issuing
> the logging request.
>
> On 4/20/07, Cheung, Quinn <QC...@rheinmetall.ca> wrote:
> > Using the PatternLayout and ConversionPattern, is there any way to
> > automatically print out the name of the logger that was used to log a
> > message?  I know I can get the name of the class which will coincide with
> > the logger name if I do:
> >
> > Logger theLogger = getLogger( TheClassName.class );
> >
> > But I'm not doing that, I'm doing:
> >
> > Logger theLogger = getLogger( "HardCodedString" );
> >
> > and I want "HardCodedString" to appear each time theLogger logs a
> > message.
> >
> > Thanks!
> >
> > Q.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Logger name in the log entry

Posted by "Cheung, Quinn" <QC...@rheinmetall.ca>.
I'm afraid that doesn't work.  As I mentioned in the original mail, I don't want the class name.  I want the name (identifier) of the logger. In my case I'm not using the class name in the call to Logger.getLogger(), therefore the name of the logger is not the same as the class name.




-----Original Message-----
From: James Stauffer [mailto:stauffer.james@gmail.com]
Sent: April 20, 2007 4:23 PM
To: Log4J Users List
Subject: Re: Logger name in the log entry


c: Used to output the category of the logging event.
C: Used to output the fully qualified class name of the caller issuing
the logging request.

On 4/20/07, Cheung, Quinn <QC...@rheinmetall.ca> wrote:
> Using the PatternLayout and ConversionPattern, is there any way to automatically print out the name of the logger that was used to log a message?  I know I can get the name of the class which will coincide with the logger name if I do:
>
> Logger theLogger = getLogger( TheClassName.class );
>
> But I'm not doing that, I'm doing:
>
> Logger theLogger = getLogger( "HardCodedString" );
>
> and I want "HardCodedString" to appear each time theLogger logs a message.
>
> Thanks!
>
> Q.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Logger name in the log entry

Posted by James Stauffer <st...@gmail.com>.
c: Used to output the category of the logging event.
C: Used to output the fully qualified class name of the caller issuing
the logging request.

On 4/20/07, Cheung, Quinn <QC...@rheinmetall.ca> wrote:
> Using the PatternLayout and ConversionPattern, is there any way to automatically print out the name of the logger that was used to log a message?  I know I can get the name of the class which will coincide with the logger name if I do:
>
> Logger theLogger = getLogger( TheClassName.class );
>
> But I'm not doing that, I'm doing:
>
> Logger theLogger = getLogger( "HardCodedString" );
>
> and I want "HardCodedString" to appear each time theLogger logs a message.
>
> Thanks!
>
> Q.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Logger name in the log entry

Posted by "Cheung, Quinn" <QC...@rheinmetall.ca>.
Using the PatternLayout and ConversionPattern, is there any way to automatically print out the name of the logger that was used to log a message?  I know I can get the name of the class which will coincide with the logger name if I do:

Logger theLogger = getLogger( TheClassName.class );

But I'm not doing that, I'm doing:

Logger theLogger = getLogger( "HardCodedString" );

and I want "HardCodedString" to appear each time theLogger logs a message.

Thanks!

Q.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RollingFileAppender

Posted by "Cheung, Quinn" <QC...@rheinmetall.ca>.
Is there a file appender that uses a FIFO type of record-rolling? What I don't like about the RollingFileAppender is that it's not a FIFO per log entry. When all the log files are full, RollingFileAppender erases the entire contents of the oldest file instead of removing 1 message at a time as needed.  Any ideas?
Thanks,

Quinn

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Time stamp in file name

Posted by James Stauffer <st...@gmail.com>.
My DateFormatFileAppender always includes the data pattern in the filename.
http://stauffer.james.googlepages.com/DateFormatFileAppender.java

On 4/20/07, Hjelmstad <je...@mdnt.com> wrote:
>
> Is there a way that I can add a timestamp to the file name that is not just a
> rolling appender?
> I may start up and stop my software 10 or more times during the course of a
> day and between those I have to remane the log file created manually.
> Does any one know of a way to automatically add a timestamp to the file name
> at the start of the software initialization?
> --
> View this message in context: http://www.nabble.com/Time-stamp-in-file-name-tf3619129.html#a10105185
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org