Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

[log4j] DailyRollingFileAppender

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for help. Appreciate it.


Chris Daq
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic