简体   繁体   中英

Grails + log4j:ERROR WARNING: Exception occured configuring log4j logging: No such property: delegate for class: java.lang.String

When I deploy my application on tomcat live, I get exception: log4j:ERROR WARNING: Exception occured configuring log4j logging: No such property: delegate for class: java.lang.String

How can I solve it? Here is the output of catalina.out

==> /data/logs/tomcat/catalina.out <==
Feb 22, 2016 5:05:08 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
[ExternalConfigLoader] INFO: File /data/conf/admin-conf.groovy
[ExternalConfigLoader] INFO: File /data/conf/my.properties
[ExternalConfigLoader] INFO: File /data/conf/check_log4j.groovy
7.791: [GC (CMS Initial Mark) [1 CMS-initial-mark: 0K(3072000K)] 1148855K(5760000K), 0.0958523 secs] [Times: user=0.56 sys=0.00, real=0.09 secs] 
7.887: [CMS-concurrent-mark-start]
7.889: [CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
7.889: [CMS-concurrent-preclean-start]
7.893: [CMS-concurrent-preclean: 0.005/0.005 secs] [Times: user=0.03 sys=0.00, real=0.01 secs] 
7.893: [CMS-concurrent-abortable-preclean-start]
log4j:ERROR WARNING: Exception occured configuring log4j logging: No such property: delegate for class: java.lang.String

==> /data/logs/tomcat/catalina.2016-02-22.log <==
22-Feb-2016 17:05:10.530 INFO [servername-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext

检查grails.config.locations :如果将配置文件保存在.properties类型的文件中,则将其更改为.groovy类型。

The problem was check_log4j.groovy contained logging setting not compatible with Config.groovy 's log4j config. OR the check_log4j.groovy is trying to override the log4j config in Config.groovy .

Detail:

Config.groovy

// Logging
final String catalinaBase = System.getProperty("catalina.base", "target")
final String logPattern = '%d [%t] %p %n\t%c.%M([...]) at Line %L %n%m%n%n'

// log4j configuration
log4j.main = {
    appenders {
        console(
                name: 'stdout',
                layout: pattern(conversionPattern: logPattern)
        )
        appender new DailyRollingFileAppender(
                name: 'appLog',
                layout: pattern(conversionPattern: logPattern),
                file: "${catalinaBase}/logs/appName/appName.log".toString()
        )
        appender new DailyRollingFileAppender(
                name: 'stacktrace',
                layout: pattern(conversionPattern: logPattern),
                file: "${catalinaBase}/logs/appName/stacktrace.log".toString()
        )
    }
    root {
        additivity = true
        if (Environment.getCurrent().equals(Environment.PRODUCTION)) {
            warn 'appLog', 'stacktrace'
        } else {
            warn 'stdout', 'appLog'
        }
    }
    error '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 'com.example.appName'
}

check_log4j.groovy

log4j {
    rootLogger="DEBUG,stdout"

    appender.stdout = "org.apache.log4j.ConsoleAppender"
    appender."stdout.layout"="org.apache.log4j.PatternLayout"
    appender."stdout.layout.conversionPattern"="%-p - %m%n"

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM