aspose file tools*
The moose likes Beginning Java and the fly likes Need help w/ timestamp incl in log file names. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help w/ timestamp incl in log file names. " Watch "Need help w/ timestamp incl in log file names. " New topic
Author

Need help w/ timestamp incl in log file names.

Dan Lajoy
Greenhorn

Joined: May 28, 2003
Posts: 19
Hello, I'm a new guy so go easy on me...

I'm working on a Websphere/RAD 6.0 J2EE application and trying to get my log files to include either a timestamp or milli-sec data within the name of the log file. I currently have it set up to include the date in the log file name only. I'm using the following info in my logging.xml file (config file used by the app):


<appender name="DAN_APPLICATION" class="org.apache.log4j.RollingFileAppender">
<param name="MaxFileSize" value="5000000" />
<param name="MaxBackupIndex" value="4" />
<param name="File" value="logs/dan.log" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.TTCCLayout">
<param name="DateFormat" value="ISO8601" />
</layout>
</appender>

This gives me a log file name of "dan02242006.log".

What I want to see is "dan02242006103100"...or something like that...basically I want to see the date and time in the log file name.

I tried replacing the parm value above from "ISO8601" to "ABSOLUTE"....but that didn't work.

I'm sure there is a very easy solution to my problem.......any suggestions would be most welcome.

Thanks!
Dan :roll:


SCJP 1.4
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

In Apache Log4J, the RollingFileAppender doesn't have a setDateFormat method. Maybe you meant to use DailyRollingFileAppender? It has a setDatePattern method which does what you ask. But it doesn't have a setMaxBackupIndex method or a SetMaxFileSize method.

(In case you didn't get it, those "param" elements in your XML each correspond to a method in the class in a standard way. So you can tell what param elements will work by looking in Log4J's API documentation for the corresponding methods.)

If you don't like how RollingFileAppender works, you can write your own subclass of it that works differently. Not a task for a complete Java beginner but not especially difficult either.
Dan Lajoy
Greenhorn

Joined: May 28, 2003
Posts: 19
Thanks for your reply.

I wonder if there is a different param name or value that I can use within the layout tag section above. I'll see if I can find anything under org.apache.log4j.TTCCLayout.
Dan Lajoy
Greenhorn

Joined: May 28, 2003
Posts: 19
I took your advice and wrote my own RollingFileAppender subclass extending RollingFileAppender. Modified my logging.xml file to what's show below and it worked like a charm. Thanks for the help.

The Ranch Rocks!!!


<appender name="MY_FRAMEWORK" class="com.mycompany.mydiv.appshared.util.MyRollingFileAppender">
<param name="MaxFileSize" value="100000000" />
<param name="File" value="C:\\myapp\\logs\\my_framework.log" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
</appender>
[ March 01, 2006: Message edited by: Dan Lajoy ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Originally posted by Dan Lajoy:
I took your advice and wrote my own RollingFileAppender subclass extending RollingFileAppender. Modified my logging.xml file to what's show below and it worked like a charm. Thanks for the help.

The Ranch Rocks!!![ March 01, 2006: Message edited by: Dan Lajoy ]
Yes, and so does open source!
sree madhavan
Greenhorn

Joined: May 02, 2006
Posts: 1
Hi,

I have a similar requirement in the application.
I have a batch process executing every night
It appends the log to a file batch.log
I need to create a log file like this
batch20060501.log

Can yo tell me the java and log4j.xml changes required to achieve this

Thanks in advace


sree
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help w/ timestamp incl in log file names.