*
The moose likes Other Open Source Projects and the fly likes Date in filename of log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Date in filename of log4j" Watch "Date in filename of log4j" New topic
Author

Date in filename of log4j

somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
I want to write my loginformation into a file with filename <month><year>.log

How can I do this using the log4j configuration file?


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Pavan Panduga
Ranch Hand

Joined: Jun 12, 2002
Posts: 68
DailyRollingFileAppender may be the option that you are looking for.

You can specify your appender in the appender option of your log4j.properties file like this

log4j.rootCategory=ALL, STDOUT, ROLLFILE
log4j.appender.ROLLFILE=org.apache.log4j.DailyRollingFileAppender

from javadoc of log4j api.

The rolling schedule is specified by the DatePattern option. This pattern should follow the SimpleDateFormat conventions. In particular, you must escape literal text within a pair of single quotes. A formatted version of the date pattern is used as the suffix for the rolled file name.

For example, if the File option is set to /foo/bar.log and the DatePattern set to '.'yyyy-MM-dd, on 2001-02-16 at midnight, the logging file /foo/bar.log will be copied to /foo/bar.log.2001-02-16 and logging for 2001-02-17 will continue in /foo/bar.log until it rolls over the next day.


Hope this helps,
Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date in filename of log4j
 
Similar Threads
[CDATA question
log4j...
Parameterize log4j appenders?
Question on IDE?
Log4j in a web application