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

Logback fails to configure in OSGI container, when multiple configurations found

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 0.9.20
    • logback-classic
    • None
    • Apache felix OSGI container, profiling with JProbe.
      Sun JDK 1.6.0_17

    Description

      When we attempt to profile our application, which runs in an Apache Felix OSGI container, using JProbe the Logback configuration fails with the following exception:

      Failed to instantiate [ch.qos.logback.classic.LoggerContext]
      Reported exception:
      java.lang.IllegalArgumentException: name
      at sun.misc.URLClassPath$Loader.findResource(URLClassPath.java:458)
      at sun.misc.URLClassPath$1.next(URLClassPath.java:195)
      at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:205)
      at java.net.URLClassLoader$3$1.run(URLClassLoader.java:393)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader$3.next(URLClassLoader.java:390)
      at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:415)
      at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:27)
      at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:36)
      at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:27)
      at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:36)
      at ch.qos.logback.core.util.Loader.getResourceOccurenceCount(Loader.java:58)
      at ch.qos.logback.classic.util.ContextInitializer.multiplicityWarning(ContextInitializer.java:131)
      at ch.qos.logback.classic.util.ContextInitializer.statusOnResourceSearch(ContextInitializer.java:154)
      at ch.qos.logback.classic.util.ContextInitializer.findConfigFileURLFromSystemProperties(ContextInitializer.java:88)
      at ch.qos.logback.classic.util.ContextInitializer.findURLOfDefaultConfigurationFile(ContextInitializer.java:97)
      at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:119)
      at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:83)
      at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:54)
      at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)
      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:261)
      at com.example.csp.gui.interfaces.logger.ABCDGUILoggerImpl.getLogger(ABCDGUILoggerImpl.java:74)
      at com.example.csp.gui.interfaces.logger.ABCDGUILoggerFactory.getLogger(ABCDGUILoggerFactory.java:51)
      at com.example.csp.gui.kernel.util.ABCDGUIKernelUtil.<clinit>(ABCDGUIKernelUtil.java:61)
      at com.example.csp.gui.kernel.context.impl.ABCDGUIKernelContextImpl.setAppBaseBundleInContext(ABCDGUIKernelContextImpl.java:207)
      at com.example.csp.gui.kernel.context.impl.ABCDGUIKernelContextImpl.init(ABCDGUIKernelContextImpl.java:93)
      at com.example.csp.gui.kernel.context.impl.ABCDGUIKernelContextImpl.<init>(ABCDGUIKernelContextImpl.java:58)
      at com.example.csp.gui.kernel.activator.impl.KernelActivatorImpl.start(KernelActivatorImpl.java:101)
      at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
      at org.apache.felix.framework.Felix.startBundle(Felix.java:1458)
      at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:984)
      at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:263)
      at java.lang.Thread.run(Thread.java:619)
      SLF4J: Class path contains multiple SLF4J bindings.
      SLF4J: Found binding in [jar:file:/C:/ngawab/wab_code/code/source/wnb-common-bundles/wnb-common-client/startup-2.0.3/csp-gui-thickclient-bootstrap-2.0.3-all.jar!/org/slf4j/impl/StaticLoggerBinder.class]
      SLF4J: Found binding in [bundle://4.0:1/org/slf4j/impl/StaticLoggerBinder.class]
      SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

      After which we get no logging at all.

      I appreciate that this will be difficult to reproduce , and I think may be related to the "bundle://" URL format not being recognised, so I had a look at the code in
      ch.qos.logback.classic.util.ContextInitializer.multiplicityWarning()
      Currently it catches an IOExeception when calling Loader.getResourceOccurenceCount(), however from the stack trace this can also throw an. IllegalArgumentException

      So could :

      try

      { urlList = Loader.getResourceOccurenceCount(resourceName, classLoader); } catch (IOException e) { sm.add(new ErrorStatus("Failed to get url list for resource [" + resourceName + "]", loggerContext, e)); }

      Become:

      try { urlList = Loader.getResourceOccurenceCount(resourceName, classLoader); }

      catch (Exception e)

      { sm.add(new ErrorStatus("Failed to get url list for resource [" + resourceName + "]", loggerContext, e)); }

      I did try this in our environment , and the logging did get successfully configured after this change ( although it wasn't pretty.... :-> )

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: