logzio / logzio-logback-appender

Logback Appender that ships logs using HTTPs bulk
Apache License 2.0
25 stars 19 forks source link

Setting appender debug property results in compilation error: "Cannot set readonly property: DEBUG for class: ch.qos.logback.classic.Level" #69

Open pajaroblanco opened 4 years ago

pajaroblanco commented 4 years ago

When using the logback.groovy configuration file, setting the debug property results in a compilation error. 'debug' is not a good property name for the LogzioLogbackAppender and should probably be changed to 'isDebug' or something similar.

appender("LOGZIO", LogzioLogbackAppender) {
    token = 'my-token'
    logzioUrl = 'https://listener-wa.logz.io:8071'
    logzioType = app
    additionalFields = "env=$environment;appStack=$stack;appOwner=$appOwner;appId=$appId"
    addHostname = true
    format = 'text'
    line = true
    debug = true //results in error
}

Error:

Reported exception:
groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: DEBUG for class: ch.qos.logback.classic.Level
    at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2715)
    at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3809)
    at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:215)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:496)
    at Script1$_run_closure1.doCall(Script1.groovy:22)
    at Script1$_run_closure1.doCall(Script1.groovy)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:37)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
    at ch.qos.logback.classic.gaffer.ConfigurationDelegate.appender(ConfigurationDelegate.groovy:143)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
    at org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod.invoke(MixinInstanceMetaMethod.java:56)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:223)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:184)
    at Script1.run(Script1.groovy:14)
    at Script1$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
    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:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
    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:67)
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
    at io.micronaut.runtime.Micronaut.<clinit>(Micronaut.java:46)
    at edu.ucr.cnc.app.Application.main(Application.groovy:12)

I have also tried setting the debug property after the appender is registered:

appender("LOGZIO", LogzioLogbackAppender) {
    token = 'my-token'
    logzioUrl = 'https://listener-wa.logz.io:8071'
    logzioType = app
    additionalFields = "env=$environment;appStack=$stack;appOwner=$appOwner;appId=$appId"
    addHostname = true
    format = 'text'
    line = true
}

LogzioLogbackAppender logzIoAppender = this.appenderList.find { it.name == 'LOGZIO' }
logzIoAppender.debug = true

The problem with this is that the underlying LogzioSender object was already built and the debug property was set to false at the time of instantiation so it makes no difference.

JDK: 11.0.7 Micronaut: 1.1.3 Logback: 1.2.3 logzio-logback-appender: 1.0.24

Doron-Bargo commented 4 years ago

Hi @pajaroblanco we are looking into this issue and will get back to you quickly

Doron-Bargo commented 4 years ago

Hi @pajaroblanco - the debug should be part of the configuration and not the code

pajaroblanco commented 4 years ago

@Doron-Bargo It is part of the configuration. Logback supports both XML configuration and Groovy configuration. When trying to set the debug property when using a groovy logback configuration file, it results in a compilation error.

http://logback.qos.ch/manual/groovy.html