Grails: Replace log4j with logback

I am trying to replace log4j in my Grails application with logback, but I always get

Embedded error: java.lang.reflect.InvocationTargetException
org.apache.log4j.LogManager

when running run-app or test-app.

I included the following in BuildConfig.groovy, which I thought was enough:

inherits("global") {
    excludes "slf4j-log4j12"
}

[...]

dependencies {
    build 'ch.qos.logback:logback-core:0.9.29', 'ch.qos.logback:logback-classic:0.9.29'
    runtime 'ch.qos.logback:logback-core:0.9.29', 'ch.qos.logback:logback-classic:0.9.29'
}

I can not find more links to Log4J and have no idea where this call is from ??

I am also trying to replace Grails slf 1.5.8 with 1.6.2 and get the following in the console, despite the slf exception from all Grails modules:

SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.

Thank you in advance for your help.

Hi

Jonas

+5
source share
5 answers

Logback 0.9.21 and higher depends on slf4j-api 1.6, which this error tells you.

Add dependencies for org.slf4j: slf4j-api: 1.6

+3
source

BuildConfig.groovy Grails 2.1.0:

inherits("global") {
    excludes 'grails-plugin-log4j'        
}

[...]

dependencies {       
    compile 'ch.qos.logback:logback-classic:1.0.6'
    runtime 'ch.qos.logback:logback-classic:1.0.6'
}

[...]

this.classLoader.rootLoader.addURL(new File("${basedir}/grails-app/conf/").toURI().toURL())

Grails grails-app/conf/logback.groovy, .

+3

logback 1.0.6. . . "logback.configurationFile = { groovy }". :

grails run-app -Dlogback.configurationFile=c:\log\logback.groovy

tomcat , .

.

0
0

:

Config.groovy

logback = {
    appenders {
        console name: 'stdout', encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n")

        rollingFile(
                name: 'fileAppender',
                file: logFileName,
                encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n"),
                triggeringPolicy: new SizeBasedTriggeringPolicy(maxFileSize: 10*1024*1024), // Max is 10 MB log files
                rollingPolicy: new FixedWindowRollingPolicy(fileNamePattern: iLogFileName)
        )
    }

    error fileAppender: 'org.codehaus.groovy.grails.web.servlet',        // controllers
            'org.codehaus.groovy.grails.web.pages',          // GSP
            'org.codehaus.groovy.grails.web.sitemesh',       // layouts
            'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
            'org.codehaus.groovy.grails.web.mapping',        // URL mapping
            'org.codehaus.groovy.grails.commons',            // core / classloading
            'org.codehaus.groovy.grails.plugins',            // plugins
            'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
            'org.springframework',
            'org.hibernate',
            'net.sf.ehcache.hibernate'

    info fileAppender: 'org.springframework.web.client',
            'com.yourpackage',
            'com.linkedin.grails'


    debug fileAppender: 'com.yourpackage',  // Set debug level for non-grails artifacts, e.g. src/groovy, under the com.yourpackage.package
            'grails.app' // Set debug level for all application artifacts

    trace fileAppender: 'org.springframework.web.client',
            'org.springframework.social',
            'com.yourpackage'

    root {
        info 'stdout', 'fileAppender'
    }
}
  1. logback :

BuildConfig.groovy

 inherits("global") {
        excludes 'grails-plugin-log4j', 'log4j'  //using logback as grails-log4j have serialization issues with spark libraries
    }

: include compile 'org.grails.plugins: logback: 0.3.1'

  • . .

  • WAR.

  • dev, logback.xml conf.

logback.xml:

<?xml version="1.0" encoding="UTF-8" ?>

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="warn">
        <appender-ref ref="STDOUT"/>
    </root>
    <shutdownHook/>
</configuration>
0

All Articles