Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultLoggingEventBuilder/Log4jEventBuilder "addArgument" with supplier behaves same as constant value. #367

Open
oravecm opened this issue Nov 18, 2023 · 1 comment
Assignees

Comments

@oravecm
Copy link

oravecm commented Nov 18, 2023

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.7</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>3.0.0-alpha1</version>
        </dependency>

DefaultLoggingEventBuilder addArgument with supplier should be executed an after calling log() not directly during "addArgument" calling, else it is same as constant value.

    @Override
    public LoggingEventBuilder addArgument(Supplier<?> objectSupplier) {
        loggingEvent.addArgument(objectSupplier.get());
        return this;
    }

should be

    @Override
    public LoggingEventBuilder addArgument(Supplier<?> objectSupplier) {
        loggingEvent.addArgument(objectSupplier);
        return this;
    }

Same behaviour is in "Log4jEventBuilder"

@ceki
Copy link
Member

ceki commented Dec 22, 2023

@oravecm Are you aware that the default implementations of org.slf4j.Logger#atTrace(), org.slf4j.Logger#atDebug(), org.slf4j.Logger#atInfo() etc. return an instance of NOPLoggingEventBuilder when the relevant level is disabled for current logger?

Thus, when DefaultLoggingEventBuilder#addArgument(Supplier<?> objectSupplier) method calls objectSupplier.get(), the event is certain to be logged.

@ceki ceki added the NOT_A_BUG label Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants