[logback-user] NPE when configuring AsyncLogger in logback.groovy after using logback.xml -> logback.groovy conversion tool

Ceki Gülcü ceki at qos.ch
Sun Mar 8 10:15:44 CET 2015


Hi Mik,
FYI, the translator scipt now correctly handles appender-ref elements.
--
Ceki

On 3/5/2015 21:37, Ceki Gülcü wrote:
> Hi Mik,
>
> The groovy produced by the translator is incorrect. It should be
>
> appender("ASYNC-FILE", AsyncAppender) {
>      appenderRef(["FILE"])
> }
>
> Note the "appenderRef" instead of appender-ref
>
> Best regards,
> --
> Ceki
>
>
> On 3/5/2015 17:07, Mik Quinlan wrote:
>> Hi All
>>
>> Versions used:
>>
>> Java: 1.8.0_25
>> logback-core/classic: 1.1.2
>> groovy-all: 2.4.1
>>
>> I hope somebody can help.  I used the logback.xml -> logback.groovy
>> script to convert my log configuration, which produced:
>>
>> //
>> // Built on Thu Mar 05 16:07:54 CET 2015 by logback-translator
>> // For more information on configuration files in Groovy
>> // please seehttp://logback.qos.ch/manual/groovy.html
>>
>> // For assistance related to this tool or configuration files
>> // in general, please contact the logback user mailing list at
>> //http://qos.ch/mailman/listinfo/logback-user
>>
>> // For professional support please see
>> //http://www.qos.ch/shop/products/professionalSupport
>>
>> importch.qos.logback.classic.AsyncAppender
>> importch.qos.logback.classic.encoder.PatternLayoutEncoder
>> importch.qos.logback.core.rolling.RollingFileAppender
>> importch.qos.logback.core.rolling.TimeBasedRollingPolicy
>> importch.qos.logback.core.status.OnConsoleStatusListener
>>
>> import staticch.qos.logback.classic.Level.INFO
>>
>> statusListener(OnConsoleStatusListener)
>>
>> appender("FILE", RollingFileAppender) {
>>      file ="target/uwd.log"
>>      rollingPolicy(TimeBasedRollingPolicy) {
>>          fileNamePattern ="logFile.%d{yyyy-MM-dd}.log"
>>          maxHistory =30
>>      }
>>      encoder(PatternLayoutEncoder) {
>>          pattern ="%date{ISO8601} %-5level %thread [%logger{5}] - %msg%n"
>>      }
>> }
>> appender("ASYNC-FILE", AsyncAppender) {
>>      appender-ref("FILE")
>> }
>>
>> root(INFO, ["ASYNC-FILE"])
>>
>>
>> However, when I run Logback, I get a cryptic NPE.
>>
>> What have I done wrong with the config?
>>
>> Thanks
>>
>> Mik
>>
>> *Stack trace*
>> *==========*
>>
>> /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java
>> ...
>> 15:56:00,342 |-INFO in
>> ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2c7b5824 - Added
>> status listener of type
>> [ch.qos.logback.core.status.OnConsoleStatusListener]
>> 15:56:00,376 |-INFO in
>> ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2c7b5824 - About to
>> instantiate appender of type
>> [ch.qos.logback.core.rolling.RollingFileAppender]
>> 15:56:00,377 |-INFO in
>> ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2c7b5824 - Naming
>> appender as [FILE]
>> 15:56:00,468 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No
>> compression will be used
>> 15:56:00,471 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will
>> use the pattern logFile.%d{yyyy-MM-dd}.log for the active file
>> 15:56:00,476 |-INFO in
>> c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The
>> date pattern is 'yyyy-MM-dd' from file name pattern
>> 'logFile.%d{yyyy-MM-dd}.log'.
>> 15:56:00,476 |-INFO in
>> c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy -
>> Roll-over at midnight.
>> 15:56:00,479 |-INFO in
>> c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy -
>> Setting initial period to Thu Mar 05 15:55:35 GMT 2015
>> 15:56:00,510 |-INFO in
>> ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file
>> name: target/uwd.log
>> 15:56:00,510 |-INFO in
>> ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is
>> set to [target/uwd.log]
>> 15:56:00,519 |-INFO in
>> ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2c7b5824 - About to
>> instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
>> 15:56:00,519 |-INFO in
>> ch.qos.logback.classic.gaffer.ConfigurationDelegate at 2c7b5824 - Naming
>> appender as [ASYNC-FILE]
>> Failed to instantiate [ch.qos.logback.classic.LoggerContext]
>> Reported exception:
>> java.lang.NullPointerException
>> at
>> ch.qos.logback.core.AsyncAppenderBase.addAppender(AsyncAppenderBase.java:184)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:483)
>> at
>> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
>> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
>> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1082)
>> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:906)
>> at
>> org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:836)
>>
>> at
>> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:827)
>>
>> at
>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:164)
>>
>> at
>> ch.qos.logback.classic.gaffer.PropertyUtil.attach(PropertyUtil.groovy:48)
>> at ch.qos.logback.classic.gaffer.PropertyUtil$attach.call(Unknown Source)
>> at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
>>
>> at ch.qos.logback.classic.gaffer.PropertyUtil$attach.call(Unknown Source)
>> at
>> ch.qos.logback.classic.gaffer.ComponentDelegate.propertyMissing(ComponentDelegate.groovy:94)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:483)
>> at
>> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
>> at
>> groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:778)
>> at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1615)
>> at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3343)
>> at
>> ch.qos.logback.classic.gaffer.ComponentDelegate.getProperty(ComponentDelegate.groovy)
>>
>> at
>> org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:169)
>>
>> at groovy.lang.Closure.getPropertyTryThese(Closure.java:322)
>> at groovy.lang.Closure.getPropertyDelegateFirst(Closure.java:312)
>> at groovy.lang.Closure.getProperty(Closure.java:297)
>> at
>> org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:47)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
>>
>> at Script1$_run_closure2.doCall(Script1.groovy:51)
>> at Script1$_run_closure2.doCall(Script1.groovy)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:483)
>> at
>> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
>> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
>> at
>> org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
>>
>> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:906)
>> at
>> org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
>>
>> at
>> ch.qos.logback.classic.gaffer.ConfigurationDelegate.appender(ConfigurationDelegate.groovy:141)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:483)
>> at
>> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
>> at
>> org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod.invoke(MixinInstanceMetaMethod.java:53)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:313)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
>>
>> at
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
>>
>> at Script1.run(Script1.groovy:50)
>> at Script1$run.call(Unknown Source)
>> at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
>>
>> 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:77)
>>
>> at
>> ch.qos.logback.classic.gaffer.GafferConfigurator$run.callCurrent(Unknown
>> Source)
>> at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
>>
>> 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:44)
>>
>> at
>> ch.qos.logback.classic.gaffer.GafferUtil.runGafferConfiguratorOn(GafferUtil.java:43)
>>
>> at
>> ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:66)
>>
>> 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:129)
>> at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
>> at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
>> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
>> at
>> com.github.tomakehurst.wiremock.common.Slf4jNotifier.<clinit>(Slf4jNotifier.java:23)
>>
>> at
>> com.github.tomakehurst.wiremock.core.WireMockConfiguration.<init>(WireMockConfiguration.java:52)
>>
>> at
>> com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig(WireMockConfiguration.java:65)
>>
>> at com.....RunIntegrationTest.<clinit>(RunIntegrationTest.java:19)
>> at sun.misc.Unsafe.ensureClassInitialized(Native Method)
>> at
>> sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
>>
>> at
>> sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
>>
>> at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1082)
>> at java.lang.reflect.Field.getFieldAccessor(Field.java:1063)
>> at java.lang.reflect.Field.get(Field.java:387)
>> at org.junit.runners.model.FrameworkField.get(FrameworkField.java:69)
>> at
>> org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:156)
>>
>> at org.junit.runners.ParentRunner.classRules(ParentRunner.java:215)
>> at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:203)
>> at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:163)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:308)
>> at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
>> at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
>> at
>> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
>>
>> at
>> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
>>
>> at
>> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:483)
>> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
>>
>> Thanks
>>
>> Mik
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://mailman.qos.ch/mailman/listinfo/logback-user
>>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user


More information about the Logback-user mailing list