【问题标题】:Grails logging configuration with different appenders具有不同附加程序的 Grails 日志记录配置
【发布时间】:2012-09-28 01:36:22
【问题描述】:

这是我当前的 log4j 配置。问题是特定于开发的部分。

log4j = {
    appenders {
        console name:'stdout',
                threshold: org.apache.log4j.Level.ERROR

        rollingFile name: "appenderAccessLog",
 ...                    
        rollingFile name: "appenderAppLog",
    ...              

        environments {
            development{
                rollingFile name: "appenderDebugLog",
                    threshold: org.apache.log4j.Level.DEBUG,
                    ....
            }
        }

    }


    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'



    environments {
        production {
            // Override previous setting for 'grails.app.controller'
            root {
                error 'appenderAppLog','stdout'
                additivity = false
            }

        }              
                  debug additivity: false, stdout :['mycompany',
                     'mycompany.security',
                     'mycompany.common',
                     'grails.app.services.mycompany.services']

            debug additivity: false, appenderDebugLog :['mycompany',
                'mycompany.security',
                'mycompany.common',
                'grails.app.services.mycompany.services']

            root {
                error 'appenderAppLog','stdout'
                additivity = true
            }

现在您可以在上面看到 2 个调试语句,其中包含特定的包重定向到附加程序。 现在,如果我想对包 XXX 使用调试并发送到附加程序 A 和 B,我将不得不使用上述定义 - 它是 debugg appender1: XXX 和 debug appender2: XXX 包的重复。

我检查了 grails 日志 - 理想情况下,以下内容应该可以解决额外的调试/附加语句: 错误org.springframework

                    debug mycompany.packagenames...

        root {
            error 'appenderAppLog','stdout'
                            debug 'appenderDebugLog', 'stdout'
            additivity = true
        }

但是当我这样做时实际发生的是错误类别中列出的所有包 - 开始将调试消息发送到 appenderDebugLog 文件。当我在定义每个级别时明确说明不同的包时 - 为什么根附加程序中的调试配置会产生这个问题?。

请指导。

【问题讨论】:

    标签: grails log4j


    【解决方案1】:

    不确定是否是这种情况,但可能将所有包规范移至 appendersroot 部分下方会有所帮助。 在 root 中同时指定 stdouterrordebug 看起来是多余的。

    还有一个选项可以为细粒度配置指定特定于 appender 的定义(例如 http://snipplr.com/view/63391/grails-log4j-for-different-environments--an-example/ )。

    【讨论】:

    • 尝试将所有包移动到附加程序和根目录下 - 仍然观察到相同的行为。接下来将尝试链接。
    【解决方案2】:

    在我使用 Grails 2 进行的测试中,log4j 部分中的 environments 部分似乎不适用于附加程序。但是,您可以在根 environments 部分中创建单独的 log4j 配置,但不幸的是,这意味着您必须复制所有内容,例如

    environments {
        development {
            log4j {
                console name:'stdout',
                    threshold: org.apache.log4j.Level.ERROR
    
                rollingFile name: "appenderAccessLog",
    
                rollingFile name: "appenderAppLog",
    
                rollingFile name: "appenderDebugLog",
                    threshold: org.apache.log4j.Level.DEBUG,
                    ....
        }
        production {
            log4j {
                console name:'stdout',
                    threshold: org.apache.log4j.Level.ERROR
    
                rollingFile name: "appenderAccessLog",
    
                rollingFile name: "appenderAppLog",
            }
        }
    }
    

    https://grails.github.io/grails2-doc/2.5.x/guide/conf.html#environments

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 2018-08-09
      • 2017-02-03
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多