logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Unable to create detached markers via log4j-slf4j-impl 2.1.
Date Mon, 10 Nov 2014 20:46:31 GMT
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 <dkoch@ezakus.com> 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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message