Bug 45982

Summary: Support %X layout specification to output all MDC key-value pairs
Product: Log4j - Now in Jira Reporter: Curt Arnold <carnold>
Component: LayoutAssignee: log4j-dev <log4j-dev>
Status: RESOLVED FIXED    
Severity: normal CC: baerrach
Priority: P2    
Version: 1.2   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X 10.4   

Description Curt Arnold 2008-10-09 15:47:26 UTC
log4j 1.2's PatternLayout supports %X{keyname}, but if a keyname is unspecified, Map.get(null) is called which may throw a NullPointerException or at best will return null.  log4j 1.3's PatternLayout and extras EnhancedPatternLayout will output all key-value pairs in braces like "{{key1,val1}{key2,val2}}".  This patch adds the log4j 1.3/EnhancedPatternLayout behavior, in addition, it sorts the keys alphabetically.
Comment 1 Curt Arnold 2008-10-09 15:52:26 UTC
Committed in rev 703285
Comment 2 baerrach 2011-09-09 06:51:11 UTC
Curt, is there a reason for the format chosen for %X.

I guess I was expecting key=value.
Comment 3 Curt Arnold 2011-09-10 04:16:26 UTC
This was a backport of log4j 1.3's (now long abandoned) behavior which predates my involvement with the project. I intentionally mimicked log4j 1.3, but I don't know why that format was used in log4j 1.3.
Comment 4 baerrach 2011-09-14 05:58:47 UTC
Ahh, guess I was expecting something like logback does with key=value so I dont have to train log file analysers (e.g. Splunk) on how to interpret the MDC values.