logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject Re: MDC signature change in log4j v1.3
Date Fri, 17 Dec 2004 14:44:15 GMT

Hello Hein,

Thank  you for your  informative and  precise message.   The signature
change in of  the MDC.put and MDC.get messages in  1.3 has two, albeit
partial, justifications.

First, in log4j  1.3 you can attach properties  to a logger repository
so that all  components attached to that repository,  such as loggers,
appenders, layouts, inherit those  properties.  However, the values of
these  properties  are  of  type  String. When  log4j  1.3  internally
processes  logging  events, the  MDC  properties and  loggerRepository
properties  are  viewed  as  properties  of the  logging  event  being
processed.  There is no  distinction between properties originating in
the   MDC  and   those  properties   originating  in   the  containing
LoggerRepository.  In  short, the MDC  properties and LoggerRepository
properties  are  merged  inside   the  logging  event.   This  merging
operation is  easier to  do if the  values are  all of the  same type,
namely String.

The  second  reason   has  to  do  with  the   way  LoggingEvents  are
serialized. Data  supplied by the user  such as MDC  properties or the
event's message  are transformed into type  String before transmission
over the wire.

So it seemed reasonable to impose  that the MDC data be of type String
right from the start. However, your remarks show that this premise has
important  drawbacks from  the  user's perspective,  which  I have  to
admit, I was not aware of.

If  the  overhead  incurred  while  merging  the  MDC  properties  and
LoggerRepository properties  increases significantly when  the type of
MDC  properties  is  Object   instead  of  String,  then  the  current
signatures  are preferable.  However,  if the  additional overhead  is
small, then obviously we will revert to the old signature.

I am opening a bug report relative this issue.

Thanks again for your enlightening remarks,

At 01:01 PM 12/17/2004, Hein Meling wrote:
>Ciao,
>
>I've noticed that MDC.put(String, Object) has been deprecated and is
>being replaced by MDC.put(String, String) instead.  At first, I didn't
>think of this as a problem other than calling the Object.toString()
>method instead.
>
>But, later I discovered that this is flawed, because the Object might
>change its state (and hence toString() output might be different)
>between debug calls.  Consider my example:
>
>   Group g = new Group(1);
>   g.setState(IDLE);
>   MDC.put("group", g.toString());
>   log.debug("Hi");
>   g.setState(SYNC);
>   log.debug("Ciao");
>
>This sequence, will result in both debug statements printing the same
>state (IDLE) even if in SYNC state, as opposed to using the now
>deprecated method (actually the 1.3 version does not work; it does work
>in 1.2.8 though):
>
>   MDC.put("group", g);
>
>which would print the correct state.
>
>To overcome this problem, I would have to identify every location that
>modify the state of the Group object, and update the MDC entry, causing
>a lot of clutter.
>
>So to my question: is this signature change in 1.3alpha3 really
>warranted??  Is there a good reason for it?
>
>Thanks,
>
>Hein

-- 
Ceki Gülcü

   The complete log4j manual: http://qos.ch/log4j/



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


Mime
View raw message