Hi, Thanks.
When is the decide method of the filter called? Does specifying the filter information in the xml configuration file automatically call the decide method for that filter? If I need an application to use the same custom filters for processing log input at run-time (say through a telnet appender similar to what ChainSaw does) And also process pre-stored log files using the same filters while reading one line at a time, how could this be achieved? Thanks -----Original Message----- From: Scott Deboy [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 05, 2006 12:16 PM To: Log4J Users List Subject: RE: log4j custom filters how to? Try ExpressionFilter: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log 4j/filter/ExpressionFilter.java?view=markup Scott Deboy Principal Engineer COMOTIV SYSTEMS 111 SW Columbia Street Ste. 950 Portland, OR 97201 Telephone: 503.224.7496 Cell: 503.997.1367 Fax: 503.222.0185 [EMAIL PROTECTED] www.comotivsystems.com -----Original Message----- From: Shroff, Sushama [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 05, 2006 10:53 AM To: [EMAIL PROTECTED] Cc: log4j-user@logging.apache.org Subject: RE: log4j custom filters how to? Heri, Thanks a lot. I need a feature somewhat similar to Chainsaw. I need to be able to filter the logs based on the contents of the logs. For instance if my logs have some information like ( {name = 'xx',age='',......}, {name='yy',age='',........} etc.), I should be able to filter out the logs based on name first, then filter on age if a match for the name is found. For Eg, the user running the application should be able to select a parameter he wants to filter on at runtime. Suppose the user selects 'name = xx && age = xx ' as the filtering parameter for the logs, Then my custom filter should first filter based on name and then on age if a match for name exists. Is this kind of functionality possible by writing log4j custom filters? Could you provide me with some tips for the same. Thanks, sushama -----Original Message----- From: Bender Heri [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 04, 2006 2:23 AM To: Log4J Users List Subject: RE: log4j custom filters how to? If you use xml configuration file you can attach one ore more self written filter class(es): example: <appender name="CONSOLE.OUT" class="org.apache.log4j.ConsoleAppender"> <param name="target" value="System.out"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{HH:mm:ss.SSS} (%6r) %-5p %-10X{category} [%-7t] %F:%L %x - %m%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="debug"/> <param name="LevelMax" value="info"/> <param name="AcceptOnMatch" value="false"/> </filter> <filter class="ch.ergonomics.pms.common.supervision.TraceDenyFilter"/> <filter class="ch.ergonomics.pms.common.supervision.XMLDenyFilter"/> </appender> Your own filter class extends org.apache.log4j.spi.Filter and could look like this example: public class TraceAllowFilter extends Filter { /** Standard constructor */ public TraceAllowFilter() { super(); } /** * @see org.apache.log4j.spi.Filter#decide(org.apache.log4j.spi.LoggingEvent) */ public int decide( LoggingEvent aEvent ) { if ( aEvent.getMDC( PMSLogger.MDC_CATEGORY ) == null ) { return Filter.DENY; } if ( aEvent.getMDC( PMSLogger.MDC_CATEGORY ).equals( PMSLogger.TRACE ) ) { String s = ( String ) MDC.get( PMSConfig.PROP_NAME_TRACEON ); if ( ( s != null ) && ( s.equals( "FALSE" ) ) ) { return Filter.DENY; } return Filter.NEUTRAL; } return Filter.DENY; } } it's just a sample. You have to code your own decision algorithm. Be aware that the filters can be chained. Return values of ALLOW or DENY do NOT call the next filter, only NEUTRAL will call also the next filter of the chain. Heri > -----Original Message----- > From: Shroff, Sushama [mailto:[EMAIL PROTECTED] > Sent: Monday, July 03, 2006 11:19 PM > To: log4j-user@logging.apache.org > Subject: [SPAM (Bayesain Analysis)] - log4j custom filters how to? - > Bayesian Filter detected spam > > > Hi, > > > > I am a new user to log4j. I need to write certain custom filters for > log4j and am wondering how it is to be done. > > Any help regarding the same will be appreciated. > > > > Thanks, > > Sushama Shroff > > > > --------------------------------------------------------------------- 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] --------------------------------------------------------------------- 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]