File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[log4j] DailyRollingFileAppender

 
Chris Daq
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello instead of using date pattern as "'.'yyyy-MM-dd-HH" use "'.'yyyy-MM-dd".
 
Chris Daq
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Chris Daq
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for help. Appreciate it.


Chris Daq
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic