On Fri, 9 May 2008, Erskine, Thomas (IT) wrote:

> The other logs an event to Netcool (specifying warp_message=0) and it
> works fine.  It allows you to call log like:
>
>     $logger->log($level, $msg, $key)
>
> so that you can specify a Netcool alert key.
>
> Then comes the problem: I made a configuration file including both
> appenders.  Now I lose.  The Netcool appender continues to work nicely.
> However, the file appender mashes all the args together if I specify the
> key.  Which is the expected behaviour for it, but then I can't use the
> key feature with netcool.  I could make it work by setting
> warp_message=0 on the file appender, but to do that I have to set the
> layout to NoopLayout, so I can't get nicely formatted log entries there.
>
> It seems as if there is no way to use both types of appender (with
> warp_message=0 and without) in the same config file.  Or am I missing
> something?

Hi Thomas,

It seems like you want a statement like

    $logger->log($level, $msg, $key)

to have two different meanings, depending on which appender the message
ends up at.

On the Netcool appender, you want it to use the $key for a special
purpose, on the file appender, you want it to sweep $key under the
carpet -- seems inconsistent to me, as it's not clear what another
random new appender would do with this.

For cases like this, I would stuff the Netcool key in the MDC:

    http://log4perl.sourceforge.net/d/Log/Log4perl/MDC.html

So instead of saying

    $logger->log($level, $msg, $key);

you would say

    Log::Log4perl::MDC->put("netcool-key", $key);
    $logger->log($level, $msg);

and the Netcool appender would either fetch the the key from the
MDC in its log() method and do something with it or you could access it
as %X{netcool-key} in the layout:

    http://log4perl.sourceforge.net/d/Log/Log4perl/Layout/PatternLayout.html

Would that work for you?

Can I post this message to the mailing list? Looks like this could be
useful for other folks as well.

-- Mike

Mike Schilli
[EMAIL PROTECTED]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to