Grails + log4j:错误警告:配置log4j日志记录时发生异常:没有这样的属性:类的委托:java.lang.String

时间:2016-03-01 14:20:10

标签: tomcat grails logging log4j

当我在tomcat上部署我的应用程序时,我得到异常: log4j:ERROR WARNING: Exception occured configuring log4j logging: No such property: delegate for class: java.lang.String

我该如何解决? 这是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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

问题是check_log4j.groovy包含的日志记录设置与Config.groovy的log4j配置不兼容。或者check_log4j.groovy试图覆盖Config.groovy中的log4j配置。

详情:

<强> 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"

}