Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

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

#File makes a file of the output.
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.

Regards, Swati

share|improve this question

migrated from May 28 '10 at 4:43

This question came from our site for professional and enthusiast programmers.

2 Answers 2

The DailyRollingFileAppender of Log4j does exactly what you want.

share|improve this answer
Don't forget to use the correct fileformat to name the file. – adaptr Dec 21 '11 at 8:56

Download yourself a copy of org.apache.log4j.FileAppender (example).

Copy it into your own namespace and refactor...

Comment out the 'getName' and 'setName' properties and add 'getDirectory' and 'setDirectory' properties.

The clever stuff comes when it makes the activateOptions() call and you can now dynamically create the fileName variable on the fly. In your case you'll need to use the Calendar class.

Don't forget to change the file, for example:

#File makes a file of the output.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.