logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simon <sim...@gmail.com>
Subject Using a Custom Filter
Date Thu, 13 May 2010 21:09:07 GMT
Hi log4j-users,

I'm having problems with a custom filter not working as I would expect
and would welcome any explanation you are able to give.

I have created a very simple filter that always returns Filter.ACCEPT
from within decide(), however as I raise level of my logger set in the
configuration file, to INFO for example, I no longer see any DEBUG
output. Even though my filter should log all messages, it appears
something else with Log4j is still making a greaterThanOrEqual
comparison and stopping below threshold messages from reaching my
filter.

Any explanation on what else I need to do/extend to make things work
as I want will be gratefully received.

thanks,

Simon


>

here's my code if it's any help:

package org.logging.test;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class TestLogger {
       static Logger logger = Logger.getLogger(TestLogger.class);

       public static void main(String[] args) {
               String filename = "log.xml";
               DOMConfigurator.configure(filename);

               logger.fatal("fatal");
               logger.error("error");
               logger.info("info");
               logger.debug("debug");
       }
}


my filter:

package org.logging.test;

import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;

public class BitFilter extends Filter {
       public int decide(LoggingEvent aEvent) {
               return Filter.ACCEPT;
       }
}


my log.xml config file:

<?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="consoleTest" class="org.apache.log4j.ConsoleAppender">
       <param name="Target" value="System.out"/>
       <layout class="org.apache.log4j.PatternLayout">
           <param name="ConversionPattern" value="%-5p %c{1} >>>> %m%n"/>
       </layout>
       <filter class="org.logging.test.BitFilter" />
   </appender>
   <logger name="org.logging.test.TestLogger" additivity="false">
       <level value="INFO"/>
       <appender-ref ref="consoleTest" />
   </logger>
</log4j:configuration>

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


Mime
View raw message