-
Notifications
You must be signed in to change notification settings - Fork 170
Description
I get an exception in org.openscience.cdk.tools.LoggingTool.
The exception occurs in line 177 in CDK version 271:
Configurator.setLevel(log4jLogger.getName(), Level.WARN);
java.lang.ClassCastException: class org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to class org.apache.logging.log4j.core.LoggerContext (org.apache.logging.slf4j.SLF4JLoggerContext and org.apache.logging.log4j.core.LoggerContext are in unnamed module of loader 'app')
Here is some debugging output from log4j2, the message from CDK written to stderr and the first (of many) lines that are written to the log by CDK:
DEBUG StatusLogger org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!
DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
WARN StatusLogger Multiple logging implementations found:
Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10
Factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory, Weighting: 15
Using factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory
DEBUG StatusLogger Took 0.124734 seconds to load 250 plugins from jdk.internal.loader.ClassLoaders$AppClassLoader@73d16e93
DEBUG StatusLogger PluginManager 'Lookup' found 16 plugins
DEBUG StatusLogger AsyncLogger.ThreadNameStrategy=UNCACHED (user specified null, default is UNCACHED)
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
Could not read the System property used to determine if logging should be turned on. So continuing without logging.
Could not read the System property used to determine if logging should be turned on. So continuing without logging.
12:38:28.096 [Test worker] DEBUG org.openscience.cdk.DynamicFactory - registered 'IAtom' with 'Atom' implementation
The exception results in the logging level for the loggers used by all CDK classes not being configured correctly by the if/else clause that calls Configurator.setLevel (lines 174-178 in LoggingTool) which leaves the logging level at its default value.
Unfortunately, in case of running tests with gradle this default value for the logging level seems to be DEBUG when running tests and clutters the output to the extent of making it unreadable.
My application uses Spring Boot which results in the following logging libraries to be on the classpath:
ch.qos.logback:logback-classic:1.2.11
ch.qos.logback:logback-core:1.2.11
org.apache.logging.log4j:log4j-api:2.17.2
org.apache.logging.log4j:log4j-core:2.17.2
org.apache.logging.log4j:log4j-to-slf4j:2.17.2
org.apache.logging.log4j:log4j-1.2-api:2.17.2
org.slf4j:slf4j-api:1.7.36
org.slf4j:jul-to-slf4j:1.7.36
commons-logging:commons-logging:1.2
org.jboss.logging:jboss-logging:3.4.1.Final -> 3.4.3.Final
These different logging libraries are pulled in by various dependencies as transitive dependencies.
Any help is appreciated, in particular:
- Is there a way to fix the ClassCastException?
- Where is the logging level DEBUG set that the LoggingTool defaults to?
- A helpful workaround for me would be to change the logging level of the LoggingTool. How can I do this?