logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hein Meling <mel...@acm.org>
Subject MDC signature change in log4j v1.3
Date Fri, 17 Dec 2004 12:01:44 GMT
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



---------------------------------------------------------------------
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