[slf4j-user] Correct usage of Marker interfaces

Ceki Gulcu ceki at qos.ch
Tue Jul 14 18:31:16 CEST 2009


Jeffrey Sinclair wrote:
> 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).    

Hello Jeffrey,

As long as your custom marker implements the org.slf4j.Marker
interface, logback does not care. You do not need to necessarily go
through MarkerFactory to manufacture custom markers. MarkerFactory
offers an API to obtain markers, but otherwise there is nothing
special about MarkerFactory.

I am quite intrigued. Could you kindly provide more details about what
you are trying to do? What is your use case? What do property1,
property2 and property3 mentioned above contain? Of which type are
they, e.g. Integer, String, ...?

HTH,

> Jeff

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the slf4j-user mailing list