简体   繁体   English

如何使用Log4J禁用从不同模块的日志记录,例如防止“资源”的日志

[英]How to Disable Logging from Different Modules using Log4J Such as Preventing Logs for 'Resources'

I am working on Grails application with resources plugin and Log4j for logging. 我正在使用资源插件和Log4j进行日志记录的Grails应用程序。 I want to disable logging from resources plugin as it's not useful for me and just filling my logging file with useless information. 我想禁用资源插件中的日志记录,因为它对我没用,只是用无用的信息填充我的日志文件。 Such as: 如:

File [file] changed. Applying changes to application.
Scheduling reload of resource files due to change of file [file]
Performing a changed file reload
Loading declared resources...
Finished changed file reload 

I don't want such information in my logs file as Its not useful for me and this is making difficult too reading other useful info in my log files. 我不希望在我的日志文件中包含这样的信息,因为它对我没用,这使我在日志文件中读取其他有用信息变得困难。

Is there any way that I may disable logging from specific modules such as resource ? 有什么办法可以禁用资源等特定模块的日志记录?

I have tried the following Solution: 我尝试了以下解决方案:

off 'grails.app.services.org.grails.plugin.resource',
'grails.app.taglib.org.grails.plugin.resource',
'grails.app.resourceMappers.org.grails.plugin.resource' 

But this didn't help me. 但这对我没有帮助。

You have tried various package/class name combinations without success. 您已尝试各种包/类名组合但未成功。 Since your sample log outputs do not include the class name, you don't know what you should target. 由于您的示例日志输出不包含类名,因此您不知道应该定位什么。 If you modify the format used for log messages, you can see the exact name you need to block. 如果修改用于日志消息的格式,则可以看到需要阻止的确切名称。

An example: 一个例子:

//time, log level, thread, class, message, newline
console name: 'myAppender', layout: pattern(conversionPattern: '%d | %p | %t | %c | %m%n')
root {
    info 'myAppender'
}

Once you do that, you should see output like this: 一旦你这样做,你应该看到这样的输出:

2015-02-17 10:53:06,536 | INFO | localhost-startStop-1 | org.hibernate.tool.hbm2ddl.SchemaUpdate | schema update complete

To suppress that line of output, you'd target 要抑制该输出线,您需要定位

org.hibernate.tool.hbm2ddl.SchemaUpdate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM