Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Appending Date in the name of created LOG4J file

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I want to ask you something if you can help me out in this.

Actually i resolved all of my issues about log4j myself, but now i have one requirement, which is as follows:

Following is my configuration file for log4j:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="FeedsAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/Temp.log" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<priority value="debug" />
<appender-ref ref="FeedsAppender"/>
</root>
</log4j:configuration>


Now it creates file called Temp.log in the logs folder but my requirement is that i want to append the date of the day when these logs would be dumped to the file name For Example, the name of the file for today would be Temp_27_07_2005.So can you tell me how can i append the date to Temp.log file.Does XML allows this? Is there any parameter which would append the date in the filename?

Its important and urgent for me so if you can please let me know, then i would be grateful..

Thanks in advance,
Saurabh
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an appender named RollingFileAppender (or something like that), which rolls over the log file at specified intervals. It can be configured to append the date to the file names once they are rolled over.
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
There is an appender named RollingFileAppender (or something like that), which rolls over the log file at specified intervals. It can be configured to append the date to the file names once they are rolled over.


Hello Ulf,
I know about DailyRollingFileAppender which rolls off each day. i.e. it renames ur test.log file to test.log.27_05_2005 but for that the program needs to be executed at the time when rolling takes place.
I tried and configured the same but it doesnt create file by the name test.log.27_05_2005 , so this is an issue.

I want that as soon as all my logs are dumped into log file, its name should be like test.log.27_05_2005.

So is any help available with sample code how we can do that.I already used DailyRollingFileAppender.

Saurabh
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic