[logback-dev] [JIRA] Commented: (LBCLASSIC-297) logback.xml not found when initialized by java agent

subes (JIRA) noreply-jira at qos.ch
Sun Oct 2 23:45:16 CEST 2011


    [ http://jira.qos.ch/browse/LBCLASSIC-297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12171#action_12171 ] 

subes commented on LBCLASSIC-297:
---------------------------------

It uses the Log4j Logger class, which is implemented by SLF4j, which is backed by logback in my setup. So its just the fact that the javaagent initialzes logback during jvm bootstrap. Because of the wrong classloader, the logback.xml in my classpath is not found by logback.

> logback.xml not found when initialized by java agent
> ----------------------------------------------------
>
>                 Key: LBCLASSIC-297
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-297
>             Project: logback-classic
>          Issue Type: Bug
>    Affects Versions: 0.9.31
>            Reporter: subes
>            Assignee: Logback dev list
>
> 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 at 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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list