views:

211

answers:

2

ello Everyone, I am new to using apache logger . I have downloaded the log4j-xx and i have the following text configuration file Set root logger level to DEBUG and its only appender to mainFormat.

log4j.rootLogger = TRACE, mainFormat, FILE

mainFormat is set to be a ConsoleAppender.

log4j.appender.mainFormat=org.apache.log4j.ConsoleAppender

mainFormat uses PatternLayout.

log4j.appender.mainFormat.layout=org.apache.log4j.PatternLayout
log4j.appender.mainFormat.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

File makes a file of the output.

log4j.appender.FILE=org.apache.log4j.FileAppender     
log4j.appender.FILE.File=log4j_HAPR001_OutputFile.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

i use the above config file to create the log file. Now i wanted to add the current time stamp to the log file. Is there any way to do this. If yes can some one please give me the instructions how to do. Thanks in advance.

+1  A: 

You can add the date to the pattern using this:

%utcdate{yyyy-MM-dd HH:mm:ss.fff}

To see it in context, here is a complete PatternLayout conversion pattern:

%utcdate{yyyy-MM-dd HH:mm:ss.fff} %-5level [%thread] - %type.%method - %message%newline
Cocowalla
I am sorry about the question is ambiguous. I want the filename with the time stamp for example like systemout2006-12-09.log file... Some thing similar to this....I would really appreciate if some one can answer my question...
swati
Then Aaron's answer is what you are looking for
Cocowalla
A: 

To add a timestamp to the name of a logfile, use DailyRollingFileAppender (see the docs how to configure it)

Aaron Digulla