[logback-user] logback.groovy configuration throws errors

Tompi Mat thauer.spam at gmail.com
Wed Nov 9 18:57:35 CET 2011


Hi

Thanks a lot for the prompt reply!  What I don't quite understand at
this point is users are encouraged to use them or not.

It looks like logback.groovy files are in the way, anyhow - I am not
explicitly executing it but it is picked up by the HelloWorld.groovy
just to throw the error I mentioned.

I much prefer groovy DSL to XML but I have not found any clues as to how
logback.groovy is to be used and it puzzles me what the benefit of the
XML->groovy translators are?

Thanks a lot

Tamas


On 11/09/2011 04:23 PM, ceki wrote:
>
> The logback.groovy files are meant to be executed by
> GafferConfigurator. They are not standalone groovy applications.
>
> HTH,
>
> On 09.11.2011 16:20, Tompi Mat wrote:
>> Hi,
>>
>> I am trying to use logback.groovy instead of logback.xml in my groovy
>> project but I might be missing something:
>>
>> $ cat HelloWorld.groovy
>> @Grab('org.slf4j:slf4j-api:1.6.1')
>> @Grab('ch.qos.logback:logback-core:1.0.0')
>> @Grab('ch.qos.logback:logback-classic:1.0.0')
>> @Grab('ch.qos.logback:logback-examples:1.0.0')
>> import org.slf4j.Logger
>> import org.slf4j.LoggerFactory
>>
>> public class HelloWorld1 {
>>
>> public static void main(String[] args) {
>>
>> Logger logger = LoggerFactory.getLogger( "HelloWorld1" )
>> logger.warn("Hello world.")
>> }
>> }
>>
>> If I put the first example from
>> http://logback.qos.ch/manual/configuration.html of sample0.xml as
>> logback.xml, it seems to work perfect.
>>
>> If I put the logback.groovy equivalent instead, I get various errors,
>> like :
>>
>> $ groovy HelloWorld.groovy
>> Failed to instantiate [ch.qos.logback.classic.LoggerContext]
>> Reported exception:
>> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot
>> cast object 'ch.qos.logback.core.ConsoleAppender[null]' with class
>> 'ch.qos.logback.core.ConsoleAppender' to class
>> 'ch.qos.logback.core.Appender'
>> at
>> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:331)
>>
>>
>> If I only go with the simplest:
>>
>> root(DEBUG)
>>
>> then I get
>>
>> groovy.lang.MissingMethodException: No signature of method:
>> Script1.root() is applicable for argument types:
>> (ch.qos.logback.classic.Level) values: [DEBUG]
>> Possible solutions: wait(), run(), run(), wait(long),
>> print(java.lang.Object), print(java.lang.Object)
>>
>> Below is logback.groovy, could you enlighten me what I am doing wrong?
>>
>> Thanks,
>>
>> Tamas
>>
>>
>> ============================
>> @Grab('ch.qos.logback:logback-core:1.0.0')
>> @Grab('ch.qos.logback:logback-classic:1.0.0')
>> @Grab('ch.qos.logback:logback-examples:1.0.0')
>> import ch.qos.logback.classic.encoder.PatternLayoutEncoder
>> import ch.qos.logback.core.ConsoleAppender
>>
>> import static ch.qos.logback.classic.Level.DEBUG
>>
>> //appender("STDOUT", ConsoleAppender) {
>> // encoder(PatternLayoutEncoder) {
>> // pattern = "%d{HH:mm:ss.SSS} XXX [%thread] %-5level %logger{36} -
>> %msg%n"
>> // }
>> //}
>> root(DEBUG)
>>
>>
>
>



More information about the Logback-user mailing list