[logback-user] Groovy-config fails without outside code noticing.

Endre Stølsvik java at stolsvik.com
Fri Nov 18 13:39:12 CET 2011


Hi!

This groovy-file ...:

import ch.qos.logback.classic.PatternLayout
import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.encoder.LayoutWrappingEncoder

appender("STDOUT", ConsoleAppender) {
 encoder(LayoutWrappingEncoder) {
   layout(PatternLayout) {
     pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{55}.%M.%L -
%msg%n"
   }
 }
}

root(ALL, ["STDOUT"])

... apparently crashes the configuration as such:

Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
groovy.lang.MissingPropertyException: No such property: ALL for class:
Script1
    at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
    at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
    at Script1.run(Script1.groovy:13)
    at Script1$run.call(Unknown Source)
    at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
    at
ch.qos.logback.classic.gaffer.GafferConfigurator.run(GafferConfigurator.groovy:59)
    at
ch.qos.logback.classic.gaffer.GafferConfigurator$run.callCurrent(Unknown
Source)
    at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at
ch.qos.logback.classic.gaffer.GafferConfigurator.run(GafferConfigurator.groovy:37)
    at
ch.qos.logback.classic.gaffer.GafferUtil.runGafferConfiguratorOn(GafferUtil.java:44)
    at
ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:67)
    at
ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
    at
org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
    at XYZ.doLogConfig(XYZ.java:40)
    at XYZ.main(XYZ:169)


*
The problem is obviously the not-defined property "ALL". The problem I am
reporting is that this isn't caught.*


The console-dump happens in the *"We should never get here"* catch block
below:

  void init() {
    try {
      try {
        new ContextInitializer(defaultLoggerContext).autoConfig();
      } catch (JoranException je) {
        Util.report("Failed to auto configure default logger context", je);
      }
      StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
      contextSelectorBinder.init(defaultLoggerContext, KEY);
      initialized = true;
    } catch (Throwable t) {
      // we should never get here
      Util.report("Failed to instantiate [" + LoggerContext.class.getName()
          + "]", t);
    }
  }


Notice that the StatusManager does not know that the config failed:

13:32:07,643 |-INFO in ch.qos.logback.classic.LoggerContext[Emma
logcontext] - Found resource [logback.groovy] at
[file:/XYZ/target/classes/logback.groovy]
13:32:08,807 |-INFO in
ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2111e072 - About to
instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
13:32:08,809 |-INFO in
ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2111e072 - Naming
appender as [STDOUT]

Kind regards,
Endre Stølsvik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20111118/b31809d4/attachment.html>


More information about the Logback-user mailing list