Bug 45982 - Support %X layout specification to output all MDC key-value pairs
Support %X layout specification to output all MDC key-value pairs
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Layout
1.2
PC Mac OS X 10.4
: P2 normal
: ---
Assigned To: log4j-dev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2008-10-09 15:47 UTC by Curt Arnold
Modified: 2011-09-14 05:58 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.