[logback-user] logback.groovy configuration throws errors

ceki ceki at qos.ch
Wed Nov 9 16:23:24 CET 2011


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)
>
>


-- 
Ceki
http://twitter.com/#!/ceki


More information about the Logback-user mailing list