[logback-user] logback.groovy configuration throws errors

Tompi Mat thauer.spam at gmail.com
Wed Nov 9 16:20:15 CET 2011


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)









<http://logback.qos.ch/manual/configuration.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20111109/ebb1b698/attachment.html>


More information about the Logback-user mailing list