aspose file tools*
The moose likes Other Open Source Projects and the fly likes Appending Date in the name of created LOG4J file 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 "Appending Date in the name of created LOG4J file" Watch "Appending Date in the name of created LOG4J file" New topic
Author

Appending Date in the name of created LOG4J file

Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
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


Success is not doing extraordinary things but doing ordinary things extraordinarily well.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42623
    
  65
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.


Ping & DNS - my free Android networking tools app
Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
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
 
subject: Appending Date in the name of created LOG4J file