• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Need help w/ timestamp incl in log file names.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Sheriff
Posts: 28408
101
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28408
101
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic