[logback-user] Auto-append a log value
Ingo Siebert
ingo.siebert at cas.de
Wed Nov 12 11:18:01 CET 2008
ekkehard schrieb:
> Ingo Siebert schrieb:
>
>> Hi,
>>
>> I want to append automatically an additional log value for every log
>> message which is created.
>>
>> Reason is that I want to add a OSGi symbolic bundle name to every message.
>> I've seen a blog entry which solved it with a marker,
>>
> think that was my blog ;-)
>
Yes, it was. :-)
Thank you for your answer and your blog.
>> but I think it's
>> error prone because you have to add the marker yourself for every log call.
>>
>>
>>
> yes, you have to add it, but you also have to add the logger, the
> message, perhaps parameter, throwable ;-)
>
> in my projects I always follow this pattern:
> - each bundle has one bundle-Marker with symbolic name of the bundle
> - each class of a bundle has a static import of this bundle Marker
> - each class has its own logger
> then I always use logger.debug(bundleMarker, message)
>
> the good thing is that now the bundle name is in the marker and you
> could easy filter logs
>
I like the filtering too.
But it's an additional task for every logging message and that's why it
isn't perfect. Every developer has to know it if he starts to work for
the project. Additionally, we are all humans and make errors. That's why
I asked for an other solution.
>> Any idea how to do this?
>> Is it possible to set a listener for logged messages which can modify
>> the log message?
>>
>>
>>
> Riena does it the other way:
> they log using Equinox ExtendedLogService, which also includes a logger -
> and because its an OSGI LogService you can access the context of the
> bundle logging the event
> Riena has Listener to get those LogServices and then logs the bundle
> name and the logmessage
> using log4j
>
> for me using a Marker works great... and I'm also using Lilith and Joern
> will add supporting Markers to filter, copy, etc
>
More information about the Logback-user
mailing list