First, what you are wanting to do is, in fact, pretty normal.  However, by 
default the StatusLogger that Log4j uses for its components doesn’t use an 
Appender. Although the API is the same the internals of the StatusLogger are 
actually quite different than the “normal” Log4j implementation.  That said, 
the StatusLogger normally just writes to the console.  I actually doubt that 
that is where you want your debug events to go.  Most people prefer them to go 
to a rolling file.

To accomplish what you want you just need to set up filtering in your 
configuration so that the FATAL-INFO events go to one Appender and the DEBUG 
and TRACE events go to another Appender.

Ralph

> On Dec 14, 2015, at 8:34 AM, Nicholas Duane <[email protected]> wrote:
> 
> I'm curious if there is such a thing as a StatusAppender in log4j2 which, as 
> you would guess, is the appender the StatusLogger would use?
> 
> Here's what I'm trying to solve, I think.
> 
> I've been telling other developers I work with that a piece of code should 
> only write to a single logger.  The reason for this, in my mind, is that if a 
> piece of code writes to more than one logger then it essentially has routing 
> logic in it and I would rather have the routing in the configuration.  For 
> example:
> 
> try
>    {
>    logger1.info(...);
>    .
>    .
>    .
>    logger2.debug(...);
>    }
> catch(Exception e)
>    {
>    logger1.error(...);
>    }
> 
> The above code is sending debug events to a different logger than the rest of 
> the events it raises.  I would rather have the code send all events to a 
> single logger and control where those events are routed via the 
> configuration.  Feel free to let me know whether this is in line with logging 
> principles.
> 
> So here's the problem.  We've got some code which writes events to its 
> logger.  We want to capture these events centrally so we're sending them to a 
> central location via an HTTP appender.  We want to do this only for FATAL - 
> INFO events, so we're not expecting a huge load.  DEBUG events however, we'd 
> like to send to the same location as the status logger.  We can, of course, 
> just add a console appender for DEBUG events but that would have to be 
> controlled separately from the status logger and ideally it would be nice to 
> just piggy back on the status logger.  We could have this code write to its 
> private logger and the status logger for DEBUG events, but then we get into 
> the routing issue I mentioned above.  So I'm wondering, is there such a thing 
> as a StatusAppender?
> 
> Thanks,
> Nick
>                                         



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to