aspose file tools*
The moose likes Other Open Source Projects and the fly likes [log4j] DailyRollingFileAppender 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 "[log4j] DailyRollingFileAppender" Watch "[log4j] DailyRollingFileAppender" New topic
Author

[log4j] DailyRollingFileAppender

Chris Daq
Greenhorn

Joined: Dec 01, 2009
Posts: 5
Hello.

I need little help with log4j. I have application that uses log4j to write logs to files. I want to create a new log file with date every time Tomcat is restarted. I've tried something like this:

but it creates file every hour. Please help


Thanks,
Chris Daq
Pallu Sagar
Greenhorn

Joined: Dec 04, 2009
Posts: 16
Hello instead of using date pattern as "'.'yyyy-MM-dd-HH" use "'.'yyyy-MM-dd".


-Sagar
Chris Daq
Greenhorn

Joined: Dec 01, 2009
Posts: 5
Hi, thanks for the reply Pallu.

But I'm affraid that is not what I want. I need configuration that will create file every time server is restarted. So what if I restart server 4 times a day? "yyyy-MM-dd" pattern will create only one file and in that particular example I want 4 files with names like: log-2009.12.08-12.34.log, log-2009.12.08-13.44.log, log-2009.12.08-14.50.log and log-2009.12.08-17.20.log. If someone have a different solution please post.

Thanks,
Chris Daq
Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
Hi Chris,

You may extend DailyRollingFileAppender and modify as per your need.

But for the same what i did, created a folder with current time stamp and moved the log file into that folder.
Hope, this will resolve the problem of loosing time of log creation.

Thanks,
Tanzy.


Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

Chris Daq wrote:I need configuration that will create file every time server is restarted. So what if I restart server 4 times a day? "yyyy-MM-dd" pattern will create only one file and in that particular example I want 4 files with names like: log-2009.12.08-12.34.log, log-2009.12.08-13.44.log, log-2009.12.08-14.50.log and log-2009.12.08-17.20.log.


So you don't actually need a rolling appender. What you probably need is a FileAppender (or some custom version of it) with "Append" property set to false (so that every restart generates a new file) and with a dynamic initial file name (so that the file name has the timestamp appended to it).

[My Blog] [JavaRanch Journal]
Chris Daq
Greenhorn

Joined: Dec 01, 2009
Posts: 5
Thanks for help. Appreciate it.


Chris Daq
 
Consider Paul's rocket mass heater.
 
subject: [log4j] DailyRollingFileAppender