[logback-user] Possible problem with markers...

Ceki Gulcu listid at qos.ch
Sat Apr 21 22:47:35 CEST 2007

Hi Joern,

Comments inline.

Joern Huxhorn wrote:
> Hi guys.
> I did a quick'n'dirty conversion of  Chainsaw to support LOGBack- 
> instead of Log4J-Events.

Cool. I am sure there would be interest for your Chainsaw port.

> It works but I think I might have found a problem. It's also very well 
> possible that I simply don't understand a LOGBack/SLF4J concept...


> While testing my changes I tried to send some Markers, too. The first 
> problem I encountered was that the helper class 
> org.slf4j.helpers.BasicMarker has a package-private constructor. I 
> missed that MarkerFactory at that point and wrote my own SimpleMarker 
> that did essentially the same as BasicMarker. This worked but Chainsaw 
> would explode during event deserialization if my SimpleMarker class was 
> not contained in the classpath.

Given that Marker objects are serializable and that MarkerFactory is responsible 
for building and managing marker objects, you would not need your own factory.

> Is this expected behaviour or should LOGBacks SocketAppender always use 
> BasicMarker instead of a user-implemented Marker class while serializing 
> log events?

Unless there is a compelling use-case, *formally*, the only implementation that 
is currently supported is that of BasicMarker. Now, we could add support for 
other implementations but I don't see the need (at this stage). Do you?

In practice however, as long as the user's implementation of Marker is 
accessible on the classpath, then deserialization should work OK. I don't think 
logback-classic relies on the fact that the implementation of Marker is a 

> I'm really not sure at all. After all, it *could* be worthwhile to use 
> the applications original markers if there is some additional 
> functionality beside tagging a log message... but isn't that in itself a 
> misuse of the marker concept?

I would not call it a misuse. However, is there an advantage?

> Beside that, would it be possible to implement SLF4J's 
> BasicMarker.toString somewhat like that:
>   public String toString()
>   {
>       StringBuffer result = new StringBuffer();
>       result.append("BasicMarker[name=").append(name);
>       if(markers.size()>0)
>       {
>           result.append(", {");
>           boolean first = true;
>           for (Map.Entry<String, Marker> marker : markers.entrySet())
>           {
>               if (first)
>               {
>                   first = false;
>               }
>               else
>               {
>                   result.append(", ");
>               }
>               result.append(marker.getValue());
>           }
>           result.append("}");
>       }
>       result.append("]");
>       return result.toString();
>   }
> So it would print contained markers instead of the current generic 
> Object.toString()? This isn't really important but would be nice.

This functionality already existed in MarkerConverter in logback-classic. I 
moved it to within BasicMarker in SLF4J.

> Beside the mentioned problem I'm really very happy with LOGBack. I 
> switched a major project a month ago and haven't had any problems beside 
> the missing support in Chainsaw ;) . I especially love the ability to 
> change the logging configuration during runtime in a reasonable way.

Your kind words are much appreciated.

Would you care to share your port with other people? If you'd like, we could 
create a SVN account for you on our machines. As for intellectual property, as 
long as the code is licensed under Apache License (obviously with copyright 
assigned to the Apache Software Foundation), we would be OK from a legal pov.

What do you think?

> Thanks for all your work,
> Joern.
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.

More information about the Logback-user mailing list