From: Dirk L. <di...@no...> - 2003-04-08 07:37:02
|
Hi Bastiaan, > Changing the NDC and/or LoggingEvent classes for such a specific purpose > doesn't sound like a good idea. > Log4j has a class MDC ("Mapped Diagnostic Context"), besides the NDC. It > essentially is a thread specific string to string mapping. So instead of > cluttering the NDC, you can put the indentation level in a separate > mapping. You'll have to write the push() and pop() methods yourself in > this case, but that shouldn't be difficult. > At the moment, log4cpp doesn't have an MDC implementation, but it would > be easy to add one. I had a look into the MDC from log4j. I didn't knew about the MDC before. As you said, it is not difficult to add support for the MDC to log4cpp, I can do this if you like. But it seems to be like an overkill for the very trivial problem of incrementing and decremeting an indentation value. I must agree, that the MDC is a more general solution, and that log4cpp should stay as close to log4j as possible. I can not program in java, so I have one question. During logging the MDC lookup of a key is done in the current thread MDC. The MDC is not copied by default into the LoggingEvent, only explictly when using the AsyncAppender and during the writeObject method. Form the methodName I would expect that the writeObject is called during serialization of the LoggingEvent. A simple copy of the LoggingEvent would not copy the MDC. But why does log4j not serialize the threads MDC directly during the writeObject method? Why must there be a copy within the LoggingEvent object? Is the serialization prozess asynchron, or does the "defaultWriteObject" in java serialize only class member variables? But why not have a writeMDC method like there is a writeLevel method? As I said, I have no experience in java, yet :-) Dirk |