Norbert Toth-Gati wrote:
You may try to configure the following categories:

   <category name="com.mycompany">
       <priority value="DEBUG"/>
       <appender-ref ref="MAIN_LOG"/>
       <appender-ref ref="DEBUG_LOG"/>
   </category>

   <category name="com.othercompany">
       <priority value="WARN"/>
       <appender-ref ref="MAIN_LOG"/>
   </category>

   <category name="com.othercompany">
       <priority value="DEBUG"/>
       <appender-ref ref="DEBUG_LOG"/>
   </category>

It doesn't work. I end up with an empty MAIN_LOG and the following error 
message:

log4j:ERROR Attempted to append to closed appender named [MAIN_LOG].

You may need to configure all the thirdparty logs to end up in the following appenders:

   <category name="org.thirdparty">
       <priority value="ERROR"/>
       <appender-ref ref="MAIN_LOG"/>
   </category>
   <category name="org.thirdparty">
       <priority value="INFO"/>
       <appender-ref ref="DEBUG_LOG"/>
   </category>

I would prefer to have a catch-all rule. I guess that the <root> element can be used for that, but you can only have one <root> element.

Here is the complete log4j.xml I tested with:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

   <appender name="DEBUG_LOG" class="org.apache.log4j.DailyRollingFileAppender">
      <param name="File" value="debug.log" />
      <param name="Append" value="false" />
      <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d %-5p [%t] %c - %m%n"/>
      </layout>
   </appender>

   <appender name="MAIN_LOG" class="org.apache.log4j.DailyRollingFileAppender">
      <param name="File" value="main.log" />
      <param name="Append" value="false" />
      <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d %-5p [%t] %c - %m%n"/>
      </layout>
   </appender>

   <category name="com.mycompany">
       <priority value="DEBUG"/>
       <appender-ref ref="MAIN_LOG"/>
       <appender-ref ref="DEBUG_LOG"/>
   </category>

   <category name="com.othercompany">
       <priority value="WARN"/>
       <appender-ref ref="MAIN_LOG"/>
   </category>

   <category name="com.othercompany">
       <priority value="DEBUG"/>
       <appender-ref ref="DEBUG_LOG"/>
   </category>

</log4j:configuration>


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

Reply via email to