You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2023/01/14 21:16:00 UTC

[jira] [Commented] (LOG4J2-3647) Equivalence of `LogBuilder` and `Logger` calls

    [ https://issues.apache.org/jira/browse/LOG4J2-3647?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17676948#comment-17676948 ] 

Ralph Goers commented on LOG4J2-3647:
-------------------------------------

This makes no sense to me.

AbstractLogger does
{code:java}
@Override
public void info(final Marker marker, final Message message) {
    logIfEnabled(FQCN, Level.INFO, marker, message, message != null ? message.getThrowable() : null);
}

@Override
public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Message message,
        final Throwable throwable) {
    if (isEnabled(level, marker, message, throwable)) {
        logMessageSafely(fqcn, level, marker, message, throwable);
    }
}

@Override
public LogBuilder atInfo() {
    return atLevel(Level.INFO);
} 

@Override
public LogBuilder atLevel(Level level) {
    if (isEnabled(level)) {
        return getLogBuilder(level).reset(level);
    }
    return LogBuilder.NOOP;
}{code}
So in both of these cases isEnabled() is being called. In the logger.info() case if isEnabled returns false nothing is done. In the second case a NoOp LogBuilder is returned.

In both isEnabled methods the global filter will be checked and then the logger's level will be evaluated ONLY if the filter is Neutral. This is handled in the various filter implementations in PrivateConfig, such as [https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java#L502.]

Since the exact same mechanism is used to evaluate the filter and log level I fail to understand how this could be happening.

> Equivalence of `LogBuilder` and `Logger` calls
> ----------------------------------------------
>
>                 Key: LOG4J2-3647
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3647
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>            Reporter: Piotr Karwasz
>            Priority: Major
>
> The following two calls should behave in the same way:
> {code:java}
> logger.info(marker, "Hello Log4j2 Core!");
> logger.atInfo().withMarker(marker).log("Hello Log4j2 Core!");
> {code}
> If we use global filters and the filter returns {{ACCEPT}}, the first call will log a message even if the logger's level is lower than {{INFO}}. The second call will not log anything.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)