Hi Simon, I think that the level applied to a Logger instance is evaluated first so that in this case anything below INFO is dropped by the Logger and therefore the event does not get as far as being posted into the filters/appenders.
Filtering the event by setting the Logger level allows lower level events to be dropped with minimal expense. If you want your filter to make the decision, set your Logger level to include the lowest level of event you want the filter to receive. Regards Andy -----Original Message----- From: simon [mailto:[email protected]] Sent: 13 May 2010 22:09 To: [email protected] Subject: Using a Custom Filter 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: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
