Grails日志记录:多个记录器和appender [英] Grails logging: Multiple loggers and appenders

查看:120
本文介绍了Grails日志记录:多个记录器和appender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置一个Grails(2.2.0)应用程序来为特定程序包创建一个日志文件,然后使用控制台输出来执行其他任何操作。我还想确保没有任何内容传送到控制台(保持它们完全分开)。阅读文档我仍然对如何获得此信息感到困惑完成。有人可以帮助一个实现此目的的示例(使用log4j DSL)吗?

I am trying to configure a Grails (2.2.0) app to have a log file for a specific package and then use the console output for everything else. I also want to make sure that nothing that goes to the log file also goes to the console (keep them totally separate). Reading through the docs I am still a bit confused on how to get this done. Could someone help out with an example that accomplishes this (using the log4j DSL)?

推荐答案

一个href =https://stackoverflow.com/questions/3995534/send-log-output-to-different-files-in-grails-1-3-2>这个问题。以下是我在Config.groovy中结束的内容:

I got this working with help from this question. Here's what I ended up with in my Config.groovy:

log4j = {
    appenders {
        console name: 'stdout', layout: pattern(conversionPattern: '%d{yyyy-MM-dd/HH:mm:ss.SSS} [%t] %x %-5p %c{2} - %m%n')

        rollingFile name: 'extraAppender',
                conversionPattern: '%d{yyyy-MM-dd/HH:mm:ss.SSS} [%t] %x %-5p %c{2} - %m%n',
                maxFileSize: 1024,
                file: '/tmp/logs/extra.log'
    }

    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'

    trace  additivity: false, extraAppender: 'extraLogger'
}

然后在应该使用extraLogger的类中,我只需像这样去记录器:

Then in the class that's supposed to use the extraLogger, I just go the logger like this:

def extraLogger = LoggerFactory.getLogger('extraLogger')

这让我可以在控制台日志中记录更多事物并将其他特定的事物记录到另一个日志文件中,而不会在控制台日志中记录任何特定的事情。

That lets me log more things to the console and some other specific things to another log file, without any of those specific things ending up in the console log.

这篇关于Grails日志记录:多个记录器和appender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆