Try the DatedFileAppender. I'm not sure if it is already contained in the standard version or if you still have to download the class as an extension. At the end a sample of my xml config file with a DatedFileAppender and a ConsoleAppender. The occ.log for the filename will be changed to 'occ-20010919.log' for Sep-19-2001.
 
Try following code for the error logging:
 
      // make sure everything sent to System.err is logged
      System.setErr(new PrintStream(new LoggingOutputStream(Category.getRoot(), Priority.WARN), true));
Hope this helps!? Gunter
 
Here the xml file:
 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
 
<log4j:configuration debug="false">
 
        <appender name="A1" class="org.apache.log4j.DatedFileAppender">
  <param name="File" value="C:/occ/logs/occ.log"/>
                <param name="Append" value="true" />
  <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern"
                            value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
  </layout>
 </appender>
 
        <appender name="A2" class="org.apache.log4j.ConsoleAppender">
  <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern"
                            value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
  </layout>
 </appender>
 <category name="org.apache.log4j.xml">
   <priority value="info" />
      <appender-ref ref="A1" />
       <appender-ref ref="A2" />
 </category>
 <root>
    <priority value ="info" />
       <appender-ref ref="A1" />
       <appender-ref ref="A2" />
 </root>
 
</log4j:configuration>
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Lukman W. Kusuma
Sent: Thursday, September 20, 2001 10:00 PM
To: [EMAIL PROTECTED]
Subject: Beginner Questions

Dear All,

I am a new user of Log4J. I got 2 question, which might have been questions before, but I am not sure what the best pattern for my issue to start searching it.

Here are the questions :
  1. There is a requirement to use a log file with date as the filename (i.e 20010304app.log) based on current date. Could I do this with log4j? If yes, how ? With this, I don't have to bother about log4j.appender.R.MaxBackupIndex in my config anymore.
  2. Could I stream the Exception.printStackTrace() into the log4J logging system? How ?
TIA

Lukman

Reply via email to