Home > Enterprise >  Missing log output from static logger class field
Missing log output from static logger class field

Time:08-30

When executing JUnit tests in a Maven build on Jenkins some logs are not being written to the console.

class Foo {
    static final Logger log = LoggerFactory.getLogger(Foo.class);

    static Logger log() {
        return LoggerFactory.getLogger(Foo.class);
    }

    void baz() {
        log.error("error 1")
        log().error("error 2")
    }
}

Method baz is called from my JUnit test and error 2 is logged when executing the build on Jenkins, but error 1 is missing. Locally I cannot reproduce the problem. Executing the same Maven build on my machine I see the output of both logging statements.

I run the same Java version on Jenkins and locally:

OpenJDK Runtime Environment Temurin-11.0.16.1 1 (build 11.0.16.1 1)

Any pointers what could be causing this or how I could further drill down into the problem for finding the root cause?

Update: I can see that the Logger instance from the first logging statement is a different one than the one from the second logging statement.

CodePudding user response:

Turns out some other tests in our suite ends up calling LogManager.shutdown at some point. This causes the static final logger reference to become stale. Apparently this only started showing up after some other unrelated changes caused the order of test execution to change so the shutdown of the logging system would happen before the relevant logger is being used in another test.

  • Related