You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Rodolfo Gonzalez <rg...@yahoo.com> on 2009/03/15 21:00:48 UTC
Addning new fields to the logs.
Hi all,
We've been using the log4cxx library for a while in our applications. Then we had this new requirement to add some new unsupported fields in the log.
After some research we were unable to find any documentation on the subject so we had to look at the code and try to come up with a solution. We impose
yet another requirement on ourselves that is; not to change the library code and make the code as
generic as possible.
Then we decided to publish the solution in the hope somebody might find it useful. It can be found here:
http://rodolfotech.blogspot.com/2009/03/adding-new-fields-to-log4cxx-logger.html
I don't know if this is the best way to do it works for us. Any alternative approach will be highly appreciated.
Many thanks,
RODOLFO
Re: Addning new fields to the logs.
Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
On 2009-03-16 20:27, Dale King wrote:
> On Sun, Mar 15, 2009 at 4:00 PM, Rodolfo Gonzalez <rg...@yahoo.com>wrote:
>> we had this new requirement to add some new unsupported fields in the log.
>>
>> I don't know if this is the best way to do it works for us. Any alternative
>> approach will be highly appreciated.
>
> I think you want a Mapped Diagnostic Context (MDC) which lets you add
> name-value pairs in thread specific storage that you can access in the log.
>
That was my first thought too, but I was thinking of mostly static per-thread
data or even per-app data that I just init before creating child threads. I
wondered though, what about dynamic data like the time data from %r and %d. Sure
I don't need %r and %d and could do the same by hand each call in my %m data,
but I'm glad I don't have to. Knowing what the new unsupported fields were would
help me decide if MDC would have been acceptable.
I got a copy of Rodolfo's code to get a better idea of what he is talking about.
I don't have my head around all of it, but it looks clean and flexible. I
still feel like I haven't caught the full vision yet. I am left wondering why
w1-w3 formats have been reserved. Was it just to provide a testing facility as
proof of concept? I also found myself wishing for a sample implementation that
extends a the code with some dynamic runtime data not available in the
PatternLayout and not appropriate for an MDC.
--
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026
Re: Addning new fields to the logs.
Posted by Dale King <da...@gmail.com>.
I think you want a Mapped Diagnostic Context (MDC) which lets you add
name-value pairs in thread specific storage that you can access in the log.
http://logging.apache.org/log4cxx/apidocs/classlog4cxx_1_1_m_d_c.html
On Sun, Mar 15, 2009 at 4:00 PM, Rodolfo Gonzalez <rg...@yahoo.com>wrote:
>
> Hi all,
> We've been using the log4cxx library for a while in our applications. Then
> we had this new requirement to add some new unsupported fields in the log.
> After some research we were unable to find any documentation on the subject
> so we had to look at the code and try to come up with a solution. We impose
> yet another requirement on ourselves that is; not to change the library
> code and make the code as
> generic as possible.
>
> Then we decided to publish the solution in the hope somebody might find it
> useful. It can be found here:
>
>
> http://rodolfotech.blogspot.com/2009/03/adding-new-fields-to-log4cxx-logger.html
>
> I don't know if this is the best way to do it works for us. Any alternative
> approach will be highly appreciated.
>
> Many thanks,
>
> RODOLFO
>
>
>
>
--
Dale King