2014-02-06 51 views
7

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

经过一番头脑风暴后,我发现,grails文档配置不适用于我的项目。然而,一些CONFIGS变化工作的罚款(我看到屏幕上的结果):

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'] 

}

的CONFIGS像:

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

非常感谢提前。

亲切的问候, 亚历山大Davliatov。

+0

我不能立即发现问题。但是,这篇文章(尽管已经过了几年)对我来说是一个有用的参考:http://6by9.wordpress.com/2010/12/07/grails-1-3-5-log4j-dsl/ –

回答

4

开始是这样的:

log4j = { 
    root { 
     debug() 
    } 
} 

你应该得到了很多记录到您的控制台。然后,(如果适用),试试这个:

log4j = { 
    info "grails.app" 
} 

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

不要忘记在Config.groovy之间的变化之间重新启动。 Grails的2.3.5项目

+0

感谢您的回答。 我已经尝试了这种方法,并得到了很多东西。这些东西是关于资源,taglibs的......但是没有记录我的控制器/服务。 正如我上面提到的, debug'grails.app.controllers' debug'grails.app.services' 无法正常工作。 –

1

这种配置工作

// 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 
} 
} 
1

对于你的Grails版本(2.3.4 http://grails.github.io/grails-doc/2.3.4/guide/conf.html#logging)似乎问题是你继承从根配置级别。 为了避免这种情况,你需要指定可加性:假

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