Grails记录不起作用

时间:2014-02-06 09:47:55

标签: grails logging

我正在开发一个grails 2.3.4应用程序并且遇到了一些日志问题。 实际上,我根本无法配置任何日志记录(相应于http://grails.org/doc/latest/guide/conf.html#logging) - 没有输出结果。

经过一番头脑风暴后我发现,grails文档配置对我的项目不起作用。然而,一些配置变化工作正常(我在屏幕上看到了结果):

log4j = {

appenders {
    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}

root {
    error 'stdout'
    additivity = true
}

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'

debug stdout: ['edu.dm']

}

配置如:

debug stdout: ['grails.app.services', 'grails.app.services.edu']
debug stdout: ['grails.app.controllers', 'grails.app.controllers.edu']

失败。

如果有人能解释我的错误或与解释分享链接,我将非常感激。 整个项目可以在这里找到:https://github.com/AlexDavljatov/EduDM/tree/master/LoggingMiniProject

非常感谢提前。

亲切的问候, Alexander Davliatov。

3 个答案:

答案 0 :(得分:4)

像这样开始:

log4j = {
    root {
        debug()
    }
}

您应该在控制台上获得大量日志记录。然后(如果可行),试试这个:

log4j = {
    info "grails.app"
}

在输出中,您应该从控制器和服务中看到log.info。然后慢慢添加到配置。

不要忘记在Config.groovy中的更改之间重新开始。

答案 1 :(得分:1)

此配置适用于Grails 2.3.5项目

// log4j configuration
log4j = {
appenders {
    // Use if we want to prevent creation of a stacktrace.log file.
    'null' name:'stacktrace'

    // Use this if we want to modify the default appender called 'stdout'.
    console name:'stdout', layout:pattern(conversionPattern: '%d{yyyy-MM-dd HH:mm} -%x- %-5p-%-10c:%m%n')

    // Custom log file.
    /* rollingFile name:"appLog",
     file:"${globalDirs.logDirectory}${appName}.log".toString(),
     maxFileSize:'300kB',
     maxBackupIndex:1,
     layout:pattern(conversionPattern: '%d{[EEE, dd-MMM-yyyy @ HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n')*/
}

// This is for the built-in stuff and from the default Grails-1.2.1 config.
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'
 warn   'org.mortbay.log' // Jetty

error 'grails.app' // Set the default log level for our app code.

// Move anything that should behave differently into this section.
switch(Environment.current) {
    case Environment.DEVELOPMENT:
    // Configure the root logger to output to stdout and appLog appenders.
        root {
            error 'stdout'
            //,'appLog'
            additivity = true
        }
        error 'grails.plugin.springsecurity.web.filter.DebugFilter'
        error "grails.plugins.twitterbootstrap"
        debug "it.mypackage"
            debug "org.hibernate.SQL"
        debug 'grails.app.controllers'
            debug 'grails.app.services'
        debug 'grails.app.taglib'
        debug 'grails.app.conf'
        debug 'grails.app.jobs'
        break
    case Environment.TEST:
    // Configure the root logger to only output to appLog appender.
        root {
            error 'stdout'
            //,'appLog'
            additivity = true
        }
    //depend how much code write in console
            //            debug 'grails.app.controllers'
    //          debug 'grails.app.domain'
    //          debug 'grails.app.services'
    //          debug 'grails.app.taglib'
    //          debug 'grails.app.conf'
    //          debug 'grails.app.filters'
        break
    case Environment.PRODUCTION:
    // Configure the root logger to output to stdout and appLog appenders.
        root {
            error 'stdout'
            //,'appLog'
            additivity = true
        }
    error 'grails.app'
        break
}
}

答案 2 :(得分:1)

对于您的grails版本(2.3.4 http://grails.github.io/grails-doc/2.3.4/guide/conf.html#logging),问题是您从根目录继承配置级别。 为避免这种情况,您需要指定additivity:false

log4j = {
    ...
    debug additivity: false, stdout: ['grails.app.services', 'grails.app.services.edu', 'grails.app.controllers', 'grails.app.controllers.edu']
    ...
}
相关问题