Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-370

logback.xml not found when initialized by java agent

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.0.0
    • None
    • None

    Description

      datanucleus-enhancer is a java agent that manipulates java classes during jvm startup. It uses a Log4J binding, which is implemented by slf4j and delegated to logback.
      datanucleus-enhacer spams the console with unnecessary debug statements while it does its work:

      21:29:25.369 [main] DEBUG DataNucleus.ClassLoading - Class "org.eclipse.core.runtime.RegistryFactory" was not found in the CLASSPATH [Class resolver called from org.datanucleus.plugin.PluginRegistryFactory.newInstance (line=91)]
      21:29:25.374 [main] DEBUG DataNucleus.Plugin - Plugin Registry "org.datanucleus.plugin.EclipsePluginRegistry" not found. Falling back to DataNucleus registry. Reason : Class "org.eclipse.core.runtime.RegistryFactory" was not found in the CLASSPATH. Please check your specification and your CLASSPATH..
      21:29:25.375 [main] DEBUG DataNucleus.Plugin - Using PluginRegistry org.datanucleus.plugin.NonManagedPluginRegistry
      21:29:25.399 [main] DEBUG DataNucleus.ClassLoading - Class "org.eclipse.core.runtime.RegistryFactory" was not found in the CLASSPATH [Class resolver called from org.datanucleus.plugin.PluginRegistryFactory.newInstance (line=91)]
      21:29:25.400 [main] DEBUG DataNucleus.Plugin - Plugin Registry "org.datanucleus.plugin.EclipsePluginRegistry" not found. Falling back to DataNucleus registry. Reason : Class "org.eclipse.core.runtime.RegistryFactory" was not found in the CLASSPATH. Please check your specification and your CLASSPATH..
      21:29:25.400 [main] DEBUG DataNucleus.Plugin - Using PluginRegistry org.datanucleus.plugin.NonManagedPluginRegistry
      ...
      --------------------------------------------------------------------------------------------------------

      That is because logback does not find my logback.xml on the classpath:
      <configuration>
      <appender name="console"
      class="de.invesdwin.gemeinsam.log.logback.ConfiguredConsoleAppender">
      <Target>System.err</Target>
      </appender>
      <root level="WARN">
      <appender-ref ref="console" />
      </root>
      </configuration>

      --------------------------------------------------------------------------------------------------------
      This is caused by ContextInitializer.getResource() using the wrong classloader during java agent process:
      sun.misc.Launcher$AppClassLoader@28df6ccd

      which cannot resolve the classpath name:
      logback.xml

      to fix this, logback should fallback to the system classloader if the resource was not found with the specific classloader. To do this, we have to change:
      -------------------
      private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
      URL url = Loader.getResource(filename, myClassLoader);
      if (updateStatus)

      { statusOnResourceSearch(filename, myClassLoader, url); }
      return url;
      }
      -------------------
      to:
      -------------------
      private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
      URL url = Loader.getResource(filename, myClassLoader);
      if(url == null){ url = Loader.getResource(filename, ClassLoader.getSystemClassLoader()); }
      if (updateStatus) { statusOnResourceSearch(filename, myClassLoader, url); }

      return url;
      }

      to properly initialize logback during javaagent execution.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            subes subes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: