Grails 日志记录 - 只记录我的应用程序,不记录 Grails 特定的垃圾

发布于 2024-11-27 17:51:50 字数 901 浏览 3 评论 0原文

从默认日志记录配置开始,我添加了 root{} 块以打开调试级别日志记录。我为我的控制器添加了一个方法...

log4j = {
  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'
  debug 'grails.app.controller'

  root {
    debug()
  }
}

现在我可以正常调试了。但我从各地得到它。 Grails 在执行运行应用程序、清除缓存、加载 spring bean 等时经历的所有启动垃圾。我想对其进行配置,以便我获得的唯一日志记录来自我的代码。这可能吗?

Starting from the default logging config, I added the root{} block to turn on debug level logging. And I added a method for my controllers...

log4j = {
  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'
  debug 'grails.app.controller'

  root {
    debug()
  }
}

And now I get debug alright. But I get it from everywhere. All the startup junk that Grails goes through when doing a run-app, clearing cache, loading spring beans, etc. I want to configure this so the only logging I get is from my code. Is that even possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-12-04 17:51:50

在 Config.groovy 文件的 log4j 部分中,定义一个日志附加程序,如下所示:

 appender name: "appLog",
        new org.apache.log4j.DailyRollingFileAppender(
        threshold: org.apache.log4j.Level.INFO,
        datePattern: "'.'yyyy-MM-dd", 
        file: "${logDirectory}/app.log", 
        layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))

让根记录器成为根,并登录到控制台:

root {
  additivity = true
  info stdout
}

然后仅将调试添加到特定记录器中的应用程序

debug additivity:true, appLog: "grails.app"

Grails 日志部分 已更改很多,但现在几乎是最新的。

In your Config.groovy file, in a log4j section, define a log appender like this:

 appender name: "appLog",
        new org.apache.log4j.DailyRollingFileAppender(
        threshold: org.apache.log4j.Level.INFO,
        datePattern: "'.'yyyy-MM-dd", 
        file: "${logDirectory}/app.log", 
        layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))

Let the root logger be the root, and log on the console:

root {
  additivity = true
  info stdout
}

And then add debug only to your app in a specific logger

debug additivity:true, appLog: "grails.app"

The grails Logging Section has been changing a lot, but is pretty much up to date now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文