You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/03/16 21:34:53 UTC

[GitHub] [logging-log4j2] carterkozak commented on a change in pull request #770: Initial support for detached markers in SLF4J binding

carterkozak commented on a change in pull request #770:
URL: https://github.com/apache/logging-log4j2/pull/770#discussion_r828470138



##########
File path: log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jMarkerFactory.java
##########
@@ -113,26 +125,19 @@ public boolean exists(final String name) {
         return markerMap.containsKey(name);
     }
 
-    /**
-     * Log4j does not support detached Markers. This method always returns false.
-     * @param name The Marker name.
-     * @return {@code false}
-     */
     @Override
     public boolean detachMarker(final String name) {
-        return false;
+        if (name == null) {
+            return false;
+        }
+        detachedMarkers.add(name);
+        return true;
     }
 
-    /**
-     * Log4j does not support detached Markers for performance reasons. The returned Marker is attached.
-     * @param name The Marker name.
-     * @return The named Marker (unmodified).
-     */
     @Override
     public Marker getDetachedMarker(final String name) {
-        LOGGER.warn("Log4j does not support detached Markers. Returned Marker [{}] will be unchanged.", name);
-        return getMarker(name);
+        final org.apache.logging.log4j.Marker log4jMarker = MarkerManager.getMarker(name);

Review comment:
       This `MarkerManager.getMarker(name)` invocation causes the `name` to be tracked in the `org.apache.logging.log4j.MarkerManager.MARKERS` collection, the proposed change only avoids the slf4j adapters cache of markers converted into the slf4j api.
   
   For this to work, log4j2 would also need to be aware of detached markers, which would also require changes to `MarkerManager.Log4jMarker.isInstanceOf(Marker marker)` which currently does a reference equality check rather than checking the string value.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org