Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-862

Misleading error message "Log4j2 could not find a logging implementation. Please add log4j-core to the classpath."

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.1
    • Component/s: Configurators
    • Labels:
      None

      Description

      In the code out put I see
      "ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console..." followed by "java.lang.ClassCastException: org.apache.logging.log4j.simple.SimpleLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext" which means core must be on the class path as otherwise you couldn't get that class cast execption. At which point the application using Log4j2 fails to start.

      The underlying problem is org.apache.logging.log4j.LogManager assuming if org.apache.logging.log4j.util.ProviderUtil returns false for hasProviders it is because core is not on the classpath. In practice I've found that hasProviders can return false because ProviderUtil is using a different Classloader than the rest of the application. It cannot find the "META-INF/log4j-provider.properties" resource but it is on the class path.

      I think there is a problem with the logic of how the classloaders are chosen but I don't understand what Log4j is trying to do here, however I am sure the error message is confusing and misleading

        Attachments

          Activity

            People

            • Assignee:
              jvz Matt Sicker
              Reporter:
              mike1979 Michael Sutherland
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: