You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by He...@amaris.de on 2003/11/10 17:23:22 UTC
Object-based NDC
Hello log4jians,
I recently replaced our website's dubious logging-mechanism with log4j.
In the course of doing so I stumbled upon the fact that the NDC
only accepts Strings as context information.
In the case of our web-application the context information is rather
complex. It consists of all information necessary to answer a
http-request, which are :
- URL parameter
- POST parameter
- current Session state of the user
- an Access-History containing a short information about all requests
by that user in the current session
To collect all this information and transform it into a string dump
is costly, especially if all this is only necessary if there's really
a log-entry with the current NDC.
Appended is a Version of org.apache.log4j.NDC which accepts it's context
information as Object and uses that Object's toString() to get the
actual information.
The advantage is that you can push an Object-Reference and have it only
evaluated if there is really a call to NDC.get()
(If you replace NDC.pop() with NDC.popObject() which will not evaluate
the context to pop it :-)
The modified version is compatible with existing client-side-code and
should be running at same speed. (Maybe a bit faster cause it saves
one temporary String per NDC-level and uses only one temporary
StringBuffer if the NDC.get() is called)
Any Comments?
How about including this into log4j?
--
have fun,
Sven Helmberger,
AMARIS Softwareentwicklungsges. mbH
Object-based NDC, second try
Posted by He...@amaris.de.
Here's another version of NDC.java which does not include the fatal
endless recursion in pop().
I really checked the code before posting it, but somehow
the bug escaped me.
( pop() is not called in our code )
--
have fun,
Sven Helmberger,
AMARIS Softwareentwicklungsges. mbH