File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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?

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 file like this

log4j.rootCategory=ALL, STDOUT, ROLLFILE

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,
I agree. Here's the link:
subject: Date in filename of log4j
It's not a secret anymore!