Search code examples
apache-poilog4j2

How can I suppress the initial StatusLogger error message


I am using Apache POI 5.2.2 in my application. Apache POI is using log4j2 as it's internal logging mechanism for debugging. As a result log4j-api-2.17.2.jar is a required dependency. I should note here that I am not using maven, so I downloaded the POI binary distribution and include the required dependencies in the application class path.

The logging in POI is intended for POI developers and it is not recommended for normal operation (i.e. end users). For my use case I do not want to use logging at all. However, when my application first loads one of the POI classes the following message is printed on stderr:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

I don't want to add log4j-core, because I really don't want the logging. I really just want to suppress this message, because logging is irrelevant to the app. I would like to do this programmatically so as to avoid adding a config file for something that I am not using. I tried to do this by setting the log4j2.StatusLogger.level property to OFF but this did not make any difference (I also tried setting it to 0).

Is there a simple incantation that I can use to suppress the StatusLogger message? Or do I have to fully get in to the log4j2 world and code up a null logger?


Solution

  • You can disable the message by explicitly setting the logger context factory to org.apache.logging.log4j.simple.SimpleLoggerContextFactory in one of the Log4j2 property sources.

    You can, e.g., add:

    log4j2.loggerContextFactory = org.apache.logging.log4j.simple.SimpleLoggerContextFactory
    

    to a log4j2.component.properties file on your classpath.

    Edit: Since version 2.24.0 you should use the log4j.provider property instead:

    log4j.provider = org.apache.logging.log4j.simple.internal.SimpleProvider