You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Mohit Anchlia <mo...@gmail.com> on 2009/02/12 23:30:29 UTC

Log Debug and Info in 2 different files

I am trying to log DEBUG and up in one log file and INFO and up in
other log file. But it doesn't seem to be working. I have tried
various things like "Level", "Threshold", "additivity", "Priority"
etc. Nothing seems to be working. Nothing is being written to sw.log.
Only INFO and up is being written to sw_infoerr.log.

I just want DEBUG and up in sw.log and INFO and up in sw_infoerr.log

Below is the config:

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

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
   <appender name="SWITCH_LOG" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="/usr/local/tomcat/logs/sw.log"/>
      <param name="Append" value="true"/>

      <!-- Keep 50 logs, 50MB each -->
      <param name="MaxBackupIndex" value="50"/>
      <param name="MaxFileSize" value="52428800"/>

      <param name="DatePattern" value="'.'yyyy-MM-dd"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{ISO8601} %-5p
[%c{3}:%t] - %m%n"/>
      </layout>
   </appender>
   <appender name="SWITCH_LOG_1" class="org.apache.log4j.RollingFileAppender">
      <param name="File" value="/usr/local/tomcat/logs/sw_infoerr.log"/>
      <param name="Append" value="true"/>

      <!-- Keep 50 logs, 50MB each -->
      <param name="MaxBackupIndex" value="50"/>
      <param name="MaxFileSize" value="52428800"/>

      <param name="DatePattern" value="'.'yyyy-MM-dd"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{ISO8601} %-5p
[%c{3}:%t] - %m%n"/>
      </layout>
   </appender>

   <logger name="com.in.en.ef.sw" additivity="false">
	<appender-ref ref="SWITCH_LOG"/>
   </logger>

   <logger name="com.in.en.ef.sw" additivity="false">
    <level value="INFO"/>
	<appender-ref ref="SWITCH_LOG_1"/>
   </logger>
</log4j:configuration>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log Debug and Info in 2 different files

Posted by Curt Arnold <ca...@apache.org>.
On Feb 12, 2009, at 5:30 PM, Mohit Anchlia wrote:

> I am trying to log DEBUG and up in one log file and INFO and up in
> other log file. But it doesn't seem to be working. I have tried
> various things like "Level", "Threshold", "additivity", "Priority"
> etc. Nothing seems to be working. Nothing is being written to sw.log.
> Only INFO and up is being written to sw_infoerr.log.

> I just want DEBUG and up in sw.log and INFO and up in sw_infoerr.log
>

Don't have time to fix your configuration file, you need a "filter" to  
accomplish this specific goal.

You need to attach a LevelMatchFilter (from the extras companion)  
followed by a DenyAllFilt to the appenders.  Set the levelToMatch to  
the level you desire to allow through.  The filter will be checked  
after the all the other levels and thresholds, so you need to make  
sure that they are set to allow the events that you are interested in  
to get through.

Priority is an obsolete name for level.  The level of a logger  
establishes the lowest level of event that is handled by this logger  
and forwarded to its parent.

additivity determines if an event is forwarded to the parent logger  
after processing by this logger.

threshold is a level below which an event is discarded by an appender.

Search the list for LevelMatchFIlter or filter, or just look in the  
last month of archives and you should find sample files.  Also, the  
source for the extras companion should also have samples of using  
filters. 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log Debug and Info in 2 different files

Posted by Curt Arnold <ca...@apache.org>.
On Feb 12, 2009, at 5:30 PM, Mohit Anchlia wrote:

> I am trying to log DEBUG and up in one log file and INFO and up in
> other log file. But it doesn't seem to be working. I have tried
> various things like "Level", "Threshold", "additivity", "Priority"
> etc. Nothing seems to be working. Nothing is being written to sw.log.
> Only INFO and up is being written to sw_infoerr.log.
>

Bender was right.  I didn't see the "and up" in the problem description.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log Debug and Info in 2 different files

Posted by Steve Cohen <sc...@javactivity.org>.
>> I just want DEBUG and up in sw.log and INFO and up in sw_infoerr.log

Why would this not work?

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

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
   <appender name="SWITCH_LOG" class="org.apache.log4j.RollingFileAppender">
	<param name="Threshold" value="DEBUG"/>
...
   </appender>
   <appender name="SWITCH_LOG_1" class="org.apache.log4j.RollingFileAppender">
	<param name="Threshold" value="INFO"/>

...
  </appender>

   <logger name="com.in.en.ef.sw" additivity="false">
	<appender-ref ref="SWITCH_LOG"/>
	<appender-ref ref="SWITCH_LOG_1"/>
   </logger>


</log4j:configuration>

Mohit Anchlia wrote:
> I am trying to log DEBUG and up in one log file and INFO and up in
> other log file. But it doesn't seem to be working. I have tried
> various things like "Level", "Threshold", "additivity", "Priority"
> etc. Nothing seems to be working. Nothing is being written to sw.log.
> Only INFO and up is being written to sw_infoerr.log.
>
> I just want DEBUG and up in sw.log and INFO and up in sw_infoerr.log
>
> Below is the config:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>
> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
> debug="false">
>    <appender name="SWITCH_LOG" class="org.apache.log4j.RollingFileAppender">
>       <param name="File" value="/usr/local/tomcat/logs/sw.log"/>
>       <param name="Append" value="true"/>
>
>       <!-- Keep 50 logs, 50MB each -->
>       <param name="MaxBackupIndex" value="50"/>
>       <param name="MaxFileSize" value="52428800"/>
>
>       <param name="DatePattern" value="'.'yyyy-MM-dd"/>
>       <layout class="org.apache.log4j.PatternLayout">
>          <param name="ConversionPattern" value="%d{ISO8601} %-5p
> [%c{3}:%t] - %m%n"/>
>       </layout>
>    </appender>
>    <appender name="SWITCH_LOG_1" class="org.apache.log4j.RollingFileAppender">
>       <param name="File" value="/usr/local/tomcat/logs/sw_infoerr.log"/>
>       <param name="Append" value="true"/>
>
>       <!-- Keep 50 logs, 50MB each -->
>       <param name="MaxBackupIndex" value="50"/>
>       <param name="MaxFileSize" value="52428800"/>
>
>       <param name="DatePattern" value="'.'yyyy-MM-dd"/>
>       <layout class="org.apache.log4j.PatternLayout">
>          <param name="ConversionPattern" value="%d{ISO8601} %-5p
> [%c{3}:%t] - %m%n"/>
>       </layout>
>    </appender>
>
>    <logger name="com.in.en.ef.sw" additivity="false">
> 	<appender-ref ref="SWITCH_LOG"/>
>    </logger>
>
>    <logger name="com.in.en.ef.sw" additivity="false">
>     <level value="INFO"/>
> 	<appender-ref ref="SWITCH_LOG_1"/>
>    </logger>
> </log4j:configuration>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org