As far as I know, log4j does not have a ForwardingAppender concept.
However, implementing it is relatively trivial. I actually rolled my own a
few months back trying to solve the problem of over filtering.
In the end, a logger level filter still makes configuration MUCH more
straight forward, as well as providing a performance benefit. Allow me to
explain the complexity and lower efficiency of the ForwardingAppender
approach:
=
A simple configuration is like you would expect:
appender name=ROOT_APPENDER
class=com.X.log4j.appender.ForwardingAppender
appender-ref ref=FILEAPPENDER/
appender-ref ref=CONSOLEAPPENDER/
/appender
appender name=MY_FILTERED_APPENDER/
class=com.X.log4j.appender.ForwardingAppender
filter class=com.X.log4j.MyFilterForXYZDOSTUFF/
appender-ref ref=ROOT_APPENDER/
/appender
logger name=com.xyz.dostuff additivity=false
appender-ref ref=MY_FILTERED_APPENDER/
/logger
root
appender-ref ref=ROOT_APPENDER/
/root
On the surface the solution looks good. However, let's say I want to add
another appender for all classes in com.xyz
logger name=com.xyz additivity=true
appender-ref ref=XYZFILE/
/logger
Since, to prevent duplicate log entries, additivity=false for
com.xyz.dostuff, if I want the output from com.xyz.dostuff to go to XYZFILE
appender as well (since it is a subclass of com.xyz), now I need to add the
appender to com.xyz AND com.xyz.dostuff:
logger name=com.xyz additivity=true
appender-ref ref=NEW_COM_XYZ_APPENDER/
/logger
logger name=com.xyz.dostuff additivity=false
appender-ref ref=NEW_COM_XYZ_APPENDER/
appender-ref ref=MY_FILTERED_APPENDER/
/logger
Not only am I duplicating appender references and creating ever increasing
complexity, but more importantly I have the same problems as originally. I
have to filter both MY_FILTERED_APPENDER and NEW_COM_XYZ_APPENDER. Instead
of just filtering log messages once, I have to filter them twice, once for
each appender. Furthermore, instead of simply filtering log events from the
com.xyz.dostuff package, as I was before, now I am filtering all logging
events from all com.xyz.* packages due to filtering NEW_COM_XYZ_APPENDER.
===
As I state before, a Logger filter is still simpler and more efficient.
Ron Grabowski wrote:
In log4net we have a ForwardingAppender that takes a message and fowards
it to one or more other appenders. To solve the problem of not having to
apply filters twice I'd put a ForwardingAppender infront of the two other
appenders. If the message passed through the filters on the
FowardingAppender the message would be sent to the registered appenders
(in your example that would be a file and console). Is there something
equivalent to a ForwardingAppender in log4j?
--
View this message in context:
http://www.nabble.com/New-Implementation%3A-Logger-level-Filtering-tf3784606.html#a10795743
Sent from the Log4j - Users mailing list archive at Nabble.com.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]