You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Stefan Borovac <St...@t-online.de> on 2008/10/08 21:41:18 UTC

PatternLayout + MDC Problem

Hi All,

I'am currently working on a simple service which connects the
XMLSocketReceiver with a DBAppender.

I'am using the latest SNAPSHOTs from either log4j, log4j-components,
and log4j-receiver.

To test the service, I connect a ConsoleAppender to a logger to track
the transmitted packages. The ConsoleAppender is staffed with a
PatternLayout having a ConversionPattern such that the MDC should be
printed.

But the instead of the MDC being printed I end up with a NPE. This is
caused in the MDCPatternConverter which should be initialised with a
key being used later to extract values from the MDC hash. But this key
is null, causing the hash function to crash throwing a NPE.

A similar setup should work in Chainsaw. Hence I assume there will be a
solution for something selfmade (or am I a bit to optimistic).

Any help or guess is welcome. I honestly don't want to crawl through the
Chainsaw code.


Cheers
   Stefan




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: PatternLayout + MDC Problem

Posted by "Stefan.Borovac@t-online.de" <St...@t-online.de>.
Yes, its the '%X' pattern I use. And yes++, it would be benefical to
support a 
simple '%X' in the PatternLayout. So, I guess the workaround is to use
qualified 
names in the PatternLayout as I don't see any setter for the
ConversionPattern?

I hope that the DPAppender uses the new pattern .... will try it :-).

Thanks a lot
  Stefan

BTW.: I have the strange feeling that the link to the user mailing list
on your web page
is wrong. I always end up on the dev list.


On Oct 8, 2008, at 2:41 PM, Stefan Borovac wrote:

> Hi All,
>
> I'am currently working on a simple service which connects the
> XMLSocketReceiver with a DBAppender.
>
> I'am using the latest SNAPSHOTs from either log4j, log4j-components,
> and log4j-receiver.
>
> To test the service, I connect a ConsoleAppender to a logger to track
> the transmitted packages. The ConsoleAppender is staffed with a
> PatternLayout having a ConversionPattern such that the MDC should be
> printed.
>
> But the instead of the MDC being printed I end up with a NPE. This is
> caused in the MDCPatternConverter which should be initialised with a
> key being used later to extract values from the MDC hash. But this key
> is null, causing the hash function to crash throwing a NPE.
>
> A similar setup should work in Chainsaw. Hence I assume there will  
> be a
> solution for something selfmade (or am I a bit to optimistic).
>
> Any help or guess is welcome. I honestly don't want to crawl through  
> the
> Chainsaw code.
>
>
> Cheers
>  Stefan
>

Likely you have a pattern like with a "%X" with no key name (that is  
not "%X{key}").  org.apache.log4j.EnhancedPatternConverter in the  
extras companion supports just a plain "%X" and will output all  
existing key-value pairs.  It does look like the  
org.apache.log4j.PatternLayout will NPE in that case which is not  
desirable and it would be good to enhance it to support an unqualified  
%X. 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: PatternLayout + MDC Problem

Posted by Curt Arnold <ca...@apache.org>.
On Oct 8, 2008, at 2:41 PM, Stefan Borovac wrote:

> Hi All,
>
> I'am currently working on a simple service which connects the
> XMLSocketReceiver with a DBAppender.
>
> I'am using the latest SNAPSHOTs from either log4j, log4j-components,
> and log4j-receiver.
>
> To test the service, I connect a ConsoleAppender to a logger to track
> the transmitted packages. The ConsoleAppender is staffed with a
> PatternLayout having a ConversionPattern such that the MDC should be
> printed.
>
> But the instead of the MDC being printed I end up with a NPE. This is
> caused in the MDCPatternConverter which should be initialised with a
> key being used later to extract values from the MDC hash. But this key
> is null, causing the hash function to crash throwing a NPE.
>
> A similar setup should work in Chainsaw. Hence I assume there will  
> be a
> solution for something selfmade (or am I a bit to optimistic).
>
> Any help or guess is welcome. I honestly don't want to crawl through  
> the
> Chainsaw code.
>
>
> Cheers
>  Stefan
>

Likely you have a pattern like with a "%X" with no key name (that is  
not "%X{key}").  org.apache.log4j.EnhancedPatternConverter in the  
extras companion supports just a plain "%X" and will output all  
existing key-value pairs.  It does look like the  
org.apache.log4j.PatternLayout will NPE in that case which is not  
desirable and it would be good to enhance it to support an unqualified  
%X. 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org