[logback-user] Auto-append a log value

ekkehard ekkehard at gentz-software.de
Tue Nov 11 10:40:03 CET 2008


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

ekke


More information about the Logback-user mailing list