Yes, that should be documented. Log4j 2 doesn’t currently support detached 
markers. 

If you can create a Jira issue for this and why a detached marker is required 
we can consider it.  However, detached markers introduce some performance and 
thread safety issues so we would really need to understand the benefit so we 
can weigh it against the cost.

Ralph

> On Nov 10, 2014, at 9:32 AM, David KOCH <[email protected]> wrote:
> 
> Hello,
> 
> I am unable to create detached versions of existing markers when using
> log4j2 through the slf4j facade - log4j2 version is 2.1.
> 
> Example:
> 
> import org.slf4j.Marker;
> import org.slf4j.MarkerFactory;
> 
> public class TestMarker {
> 
>    public static void main(String[] args) {
>       Marker markerA = MarkerFactory.getMarker("testA");
>       Marker markerB = MarkerFactory.getMarker("testB");
>       markerA.add(markerB);
>       Marker markerANew = MarkerFactory.getDetachedMarker("testA");
>       // Iteration below will fail if this line is uncommented.
>       //System.out.println("Removing reference from detached markerA: " +
> markerANew.remove(markerB));
> 
>       System.out.println("Has reference marker A: " +
> markerA.hasReferences());
>       System.out.println("Has reference detached marker A: " +
> markerANew.hasReferences());
> 
> 
>       Iterator<Marker> mRef = markerA.iterator();
>       while (mRef.hasNext()) {
>           System.out.println(mRef.next().getName());
>       }
> 
>       mRef = markerANew.iterator();
>       while (mRef.hasNext()) {
>           System.out.println(mRef.next().getName());
>       }
> 
>    }
> 
> }
> 
> Actual output:
> 
> Has reference marker A: true
> Has reference detached marker A: true
> 
> Expected output (which I get when using native slf4j logging implementation
> logback):
> 
> Has reference marker A: true
> Has reference detached marker A: false
> 
> I am trying to keep my application log framework agnostic but it seems like
> it's not possible in this case. Since it's currently impossible via
> log4j-slf4j-impl, is there a "pure" log4j2 way of getting detached marker
> instances?
> 
> The feature is quite important to us since marker names and references both
> play important parts in how we route and parse our logs.
> 
> Thank you,
> 
> Regards,
> 
> /David


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to