[
https://issues.apache.org/jira/browse/LOG4J2-552?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13916606#comment-13916606
]
Ralph Goers commented on LOG4J2-552:
------------------------------------
The way Marker inheritance works in SLF4J is different than in Log4j. In SLF4J
you can add Marker references to a Marker. So if you have Marker A you can add
Marker B to it. Then, if you log an event with Marker A and you have a filter
that filters our events with Marker B it will filter any event that has Marker
A because it has a relationship to Marker B.
In Log4j this is expressed by creating Marker B and then creating Marker A with
Marker B as its parent. Log4j does not allow multiple relationships as SLF4J
does (primarily because marker checking is a performance bottleneck in SLF4J
because it has to lock the list of markers while checking them, thus creating
lots of contention as the number of threads increase).
As such, although you are correct that Log4j checks parents while SLF4J checks
children, there is nothing wrong with the code.
> Logic of isInstanceOf are not consistent in log4j-api's Log4jMarker and
> log4j-slf4j-impl's MarkerWrapper
> --------------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-552
> URL: https://issues.apache.org/jira/browse/LOG4J2-552
> Project: Log4j 2
> Issue Type: Bug
> Components: API, SLF4J Bridge
> Affects Versions: 2.0-rc1
> Reporter: RainJ
>
> The logic of isInstanceOf is not consistent for Marker implements in
> log4j-api's Log4jMarker and log4j-slf4j-iml's MarkerWrapper.
> In Log4jMarker
> ---------------------------------------------
> @Override
> public boolean isInstanceOf(final String name) {
> if (name == null) {
> throw new IllegalArgumentException("A marker name is
> required");
> }
> Marker toTest = this;
> do {
> if (name.equals(toTest.getName())) {
> return true;
> }
> toTest = toTest.getParent();
> } while (toTest != null);
> return false;
> }
> ---------------------------------------------
> in MarkerWrapper
> ---------------------------------------------
> @Override
> public boolean isInstanceOf(final Marker marker) {
> if (marker == null) {
> throw new IllegalArgumentException("A marker parameter is
> required");
> }
> if (marker instanceof MarkerWrapper) {
> return contains((MarkerWrapper) marker);
> } else {
> return contains(marker.getName());
> }
> }
> @Override
> public boolean isInstanceOf(final String name) {
> if (name == null) {
> throw new IllegalArgumentException("A marker name is required");
> }
> return contains(name);
> }
> -----------------------------------------
> in Log4jMarker, the isInstanceOf means the marker is instance of itself or
> its parent
> in MarkerWrapper, the isInstance of means the marker is instance of itself or
> its children
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]