Grails conversionPattern 在运行时改变

发布于 2024-09-18 23:57:51 字数 617 浏览 11 评论 0原文

为我的 grails 应用程序使用标准 log4j 配置,并使用如下自定义转换模式:

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

root {
 warn 'stdout'
 additivity = true
}

error  'org.grails.plugins.springsecurity'

error  'org.codehaus.groovy.grails.web.servlet'  //  controllers
// ...

warn   'org.mortbay.log',
 'org.apache.tomcat',
 'org.apache.tomcat.util.digester'

 debug  'grails.app'

}

我的 grails 应用程序按预期启动 .. 具有良好的 conversionPattern ... 但仅在几行日志期间 ... 最终回退到默认的 grails conversionPattern ... :-/

有什么想法吗?

Using a standard log4j configuration for my grails app, with a custom conversion pattern like that :

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

root {
 warn 'stdout'
 additivity = true
}

error  'org.grails.plugins.springsecurity'

error  'org.codehaus.groovy.grails.web.servlet'  //  controllers
// ...

warn   'org.mortbay.log',
 'org.apache.tomcat',
 'org.apache.tomcat.util.digester'

 debug  'grails.app'

}

My grails app start as expected .. with the good conversionPattern ... but only during few log lines ... to finally fallback to the default grails conversionPattern ... :-/

Any idea ?

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

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

发布评论

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

评论(1

知足的幸福 2024-09-25 23:57:55

我不用 Grails 编写代码,但我非常了解 log4j。

从表面上看,您似乎需要检查那些未按预期格式化的行。有可能,它们不会被使用 stdout 附加程序的记录器捕获。

据我所知,在我看来,也许您的警告记录器是唯一使用 stdout 附加程序的记录器。这意味着除警告之外的任何内容都不会按预期格式化。此外,库中的记录器也可能捕获一些日志语句,但不会捕获其他日志语句。


Basically, the best way to solve this is to modify your pattern to give you good information on your loggers (I would suggest replacing the %C pattern, which is very slow to execute, with %c to see the exact category that was used by the logger). Then, look at the differences between what's properly formatted and everything else.

  • 他们有共同的级别(信息、调试、错误等)吗?
  • 它们来自同一个包吗?
  • 他们是第 3 方图书馆调用吗?

找出它们的共同点,你就会发现你的错误。

I don't code in Grails but I do know log4j very well.

On the surface, it seems you need to inspect those lines that aren't formatted as expected. Chances are, they are not caught by the logger that uses your stdout appender.

From what I can piece together, it looks to me like maybe your warning logger is the only one that uses your stdout appender. Meaning anything other than warnings would not format as expected. Further, it's also possible that loggers present in your libraries catch some log statements but not others.


Basically, the best way to solve this is to modify your pattern to give you good information on your loggers (I would suggest replacing the %C pattern, which is very slow to execute, with %c to see the exact category that was used by the logger). Then, look at the differences between what's properly formatted and everything else.

  • Do they have a common level (info, debug, error, etc)?
  • Do they stem from the same package?
  • Are they 3rd party library calls?

Figure out what they have in common and you will find your error.

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