[slf4j-user] Correct usage of Marker interfaces

Jeffrey Sinclair jeff at cooljeff.co.uk
Mon Jul 13 21:45:58 CEST 2009


slf4j-user,   

I'm looking to use Markers to supplement the information that is being
logged. Most of the examples I've seen have fixed markers which don't
contain any direct context information, instead they are tags for doing
a fixed enrichment of the log message at the backend. All of the
examples I've seen also create the Markers from the MarkerFactory,
leaving it up to the backend implementation (e.g. logback) to supply a
concrete named marker instance.  

What I would like to do is enrich the information going to the back end
on a per log message basis (for example to be dealt with by a logback
appender that is aware of my marker, otherwise it is ignored). 

In order to do this I would need to pass through my own Marker
implementation which is not created by the MarkerFactory.   

For example:   

{
   CustomMarker marker = new CustomMarker();
   marker.setProperty1(...);
   marker.setProperty2(...);
   marker.setProperty3(...);
   
   logger.debug(marker, "The cat sat on the mat.");
}   

After reading through various mail threads it appears that logback is
fine doing the above. All it cares is that the object implements
Marker:  

http://www.mail-archive.com/logback-user@qos.ch/msg00642.html   

However it is not clear from the slf4j APIs if markers sent through the
logger must be created from the MarkerFactory.

Could someone clarify if Markers must be created from the MarkerFactory
or if it is fine to pass in your own implementation of Marker to be
passed to the backend (bypassing the MarkerFactory).   

Jeff




More information about the slf4j-user mailing list