[slf4j-dev] [Bug 177] New: Feature-Request: allow Object as value in MDC.put

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Sat Apr 24 11:49:44 CEST 2010


http://bugzilla.slf4j.org/show_bug.cgi?id=177

           Summary: Feature-Request: allow Object as value in MDC.put
           Product: SLF4J
           Version: 1.5.x
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: major
          Priority: P1
         Component: Core API
        AssignedTo: slf4j-dev at qos.ch
        ReportedBy: issues at wennysoft.de


Currently Log4j accepts in MDC.put java.lang.Object as value while slf4j only
accepts strings.

If you have some Information which is only needed rarely and expensive to
construct you are either forced to do a toString() for each request or you have
to fall back to the native use of log4j.

For example we have an Object which wraps a httpServletRequest and will be
inserted in the MDC via a ServletFilter in order to be used in ERROR-Level
(configured via layout of the according appender). This objects constructs a
complete request dump via toString() which is expensive as for example the
values of some parameters gets masked (e.g. passwords) for privacy. 

Using log4j this object was put in the MDC as object and toString() was only
called if the information was really needed in a log statement (which is only
the case when an unexpected error occurs and will normally not occur).

When we switched to slf4j we realized that we have to either call toString()
explicitely in the filter (which would result in an expensive calculation on
each request) or have to fall back to log4j for this case which reduces
compatibility.

I would suggest to explicitly allow MDC.put(String, Object) and delegate it
directly to the underlying implementation if it is supported. If it is not
supported the adapter could call the toString() method accepting the overhead.
(This should be documented of course!)

Are there any reasons not to support this? It is a major issue for us as we are
currently not able to switch the logging mechanism (and the functionality is
part of a library)


-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the slf4j-dev mailing list