Hi,

  I think the second xml is overwriting the appender attached to root.  I'd
use one xml file, with multiple appenders and loggers, something like this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

    <appender name="DailyLog"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File"
            value="logs/multiple/LoginTrack.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p
            %m%n"/>
        </layout>
    </appender>

    <appender name="Request"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File"
            value="logs/multiple/RequestTrack.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p
            %m%n"/>
        </layout>
    </appender>

    <logger name="logging.request">
        <level value="debug"/>
        <appender-ref ref="Request"/>
    </logger>

    <logger name="logging.dailyLog">
        <level value="debug"/>
        <appender-ref ref="DailyLog"/>
    </logger>

    <root>
        <priority value="debug"/>
    </root>
</log4j:configuration>


  In your code:

                //  Initialize the config
                //
                DOMConfigurator.configure( "java/samples/xml/multiple/multi.xml" );

                //  Get the loggers
                //
                Logger requestLogger = Logger.getLogger( "logging.request" );
                Logger dailyLogger = Logger.getLogger( "logging.dailyLog" );

                //  Write to the logs
                //
            requestLogger.debug( "request message1: DEBUG" );
            requestLogger.info( "request message2: INFO" );

            dailyLogger.debug( "dailyLog message1: DEBUG" );
            dailyLogger.info( "dailyLog message2: INFO" );

  You'll get two log files.

  I've attached the xml file and a test class.

Hope this helps
-Rich


>> -----Original Message-----
>> From: Madhava Reddy [mailto:[EMAIL PROTECTED]]
>> Sent: Saturday, January 25, 2003 12:07 PM
>> To: '[EMAIL PROTECTED]'
>> Subject: Help for starter..
>>
>>
>> Hi,
>>
>> I'm fairly new to this Log4j.
>>
>> I have several questions.
>>
>> I am using Tomcat. I have jsps and java files. I planned to use 3 logs. I
>> want to maintain Logs to Track Login Time, Logout Time in one log. Second
>> log tracks Critical Requsts of all users. Third log tracks Exceptions and
>> errors for all users.
>>
>> So, I am using DailyRollingFileAppender for these 3 logs. I am
>> configuring
>> logger by an xml file.
>>
>> Here is Loggin Track xml file. Login.xml
>> ----------------
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>>
>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
>>
>>          <appender name="DailyLog"
>> class="org.apache.log4j.DailyRollingFileAppender">
>>                  <param name="File"
>> value="D:/tomcat4110/logs/smileLogs/LoginTrack.log"/>
>>                  <layout class="org.apache.log4j.PatternLayout">
>>                      <param name="ConversionPattern" value="%d %-5p
>> %m%n"/>
>>                  </layout>
>>          </appender>
>>
>>          <root>
>>                  <priority value="debug"/>
>>                  <appender-ref ref="DailyLog"/>
>>          </root>
>> </log4j:configuration>
>> ---------------
>>
>> and Request Track xml File
>>
>> ----------
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>>
>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
>>
>>          <appender name="Request"
>> class="org.apache.log4j.DailyRollingFileAppender">
>>                  <param name="File"
>> value="D:/tomcat4110/logs/smileLogs/RequestTrack.log"/>
>>                  <layout class="org.apache.log4j.PatternLayout">
>>                      <param name="ConversionPattern" value="%d %-5p
>> %m%n"/>
>>                  </layout>
>>          </appender>
>>
>>          <root>
>>                  <priority value="debug"/>
>>                  <appender-ref ref="Request"/>
>>          </root>
>> </log4j:configuration>
>> ---------
>>
>> I create loggers in my java, like
>>
>> To get Login Track logger
>>
>> org.apache.log4j.xml.DOMConfigurator.configure("Login.xml");
>>
>> Logger loginLog = org.apache.log4j.Logger.getLogger("Login");
>>
>> and to get Request Logger
>>
>> org.apache.log4j.xml.DOMConfigurator.configure("Request.xml");
>>
>> Logger requestLog = org.apache.log4j.Logger.getLogger("Request");
>>
>> --------------
>>
>> When I use these logs like
>>
>> loginLog.debug("Testing Login Track ");
>> requestLog.debug(" Testing Request Track" );
>>
>> ---
>>
>> I'm getting two log files namely LoginTrack.log and
>> RequestTrack.log. But,
>> LoginTrack is empty and RequestTrack.log contains,
>>
>> 2003-01-25 17:54:57,486 DEBUG   Testing Login Track
>> 2003-01-25 17:54:57,486 DEBUG    Testing Request Log
>>
>> which means I am getting the same reference for the two loggers. What
>> mistake I've done? How to get 2 different instances?
>>
>> ------------
>> I receive the name of Logger as argument in Java, if I have created this
>> log, return existing, else I will create new logger and return. I will
>> maintain loggers mapping looger name -- logger.
>>
>> Please point out any mistakes or wrong apprach in the above
>> approach. Will
>> this approach creates some problems at some later poing of time?
>>
>> ---
>>
>> One more question,
>>
>> Imagine, I have successfully running tomcat with these loggers.
>> After some
>> days, the loggers size may become critical. I observed that, I can not
>> delete a log file with out stopping tomcat.. How to delete old
>> log files?
>>
>> I have more questions too.. but those are more related to Tomcat
>> than Log4j.
>> I will share those later.
>>
>> thanks for your advice..
>>
>> Madhav
>>
>>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

    <appender name="DailyLog"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File"
            value="logs/multiple/LoginTrack.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p
            %m%n"/>
        </layout>
    </appender>

    <appender name="Request"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File"
            value="logs/multiple/RequestTrack.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p
            %m%n"/>
        </layout>
    </appender>

    <logger name="logging.request">
        <level value="debug"/>
        <appender-ref ref="Request"/>
    </logger>

    <logger name="logging.dailyLog">
        <level value="debug"/>
        <appender-ref ref="DailyLog"/>
    </logger>

    <root>
        <priority value="debug"/>
    </root>
</log4j:configuration>

Attachment: LoggerTest.java
Description: Binary data

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to