You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Mark Womack <mw...@bevocal.com> on 2002/04/02 06:09:30 UTC

[SUBMIT] GenericMatchFilter.java; SetLocationInfoFilter.java; Log gerNameMatchFilter.java

Enclosed are some new versions of GenericMatchFilter.java and
SetLocationInfoFilter.java.  Also enclosed is LoggerNameMatchFilter.java
which subclasses GenericMatchFilter.java.

GenericMatchFilter and SetLocationInfoFilter are pretty much the same except
for some changes needed to get them to compile properly (deprecated options
stuff?).

LoggerNameMatchFilter subclasses GenericMatchFilter and implements code to
check the logger name in the LoggingEvent against a configured set of names.
If it startsWith() any of the configured logger names, then the event is
accepted.  Could do something similar with level matching as well, but have
not had a chance to write it yet.  Also, I don't claim that
LoggerNameMatchFilter is the most efficient piece of code, but it works as a
demonstration.

Below is a sample configuration using the above filters.  If the logger name
in the logging event matches one of the two "loggerName" parameters for the
LoggerNameMatchFilter filter, then it is configured to return NEUTRAL.
Otherwise it returns ACCEPT and the event is immediatly appended.

If the logger name matches, it continues to the second filter,
SetLocationInfoFilter, which will set the location info and let it continue
on to the appender.

<appender name="logging_server"
class="org.apache.log4j.net.SocketHubAppender">\
  <param name="port" value="5000"/>\
  <param name="locationInfo" value="false"/>\
  <filter class="org.apache.log4j.varia.LoggerNameMatchFilter">\
    <param name="loggerName" value="com.womacknet.tools.TestTool"/>\
    <param name="loggerName" value="com.womacknet.tools.TestTool2"/>\
    <param name="matchReturnValue" value="neutral"/>\
    <param name="noMatchReturnValue" value="accept"/>\
  </filter>\
  <filter class="org.apache.log4j.varia.SetLocationInfoFilter"/>\
</appender>

You can configure LoggerNameMatchFilter to return any value (accept, deny,
neutral) for match or noMatch (or even cantMatch) using the param setting,
thus controlling the flow of logging events as desired at runtime.

Again, I think these are generally useful classes and should be considered
for the main package, but you decide.  Let me know if you have any
questions.

-Mark