简体   繁体   English

如何在第三方库中禁用Apache Commons / Log4J日志记录?

[英]How can I disable Apache Commons / Log4J logging in third party libraries?

Is there a Apache Commons / Log4J logging API method which can be used to disable all logging completely, even for loggers which are in third party libraries? 是否有Apache Commons / Log4J日志记录API方法可用于完全禁用所有日志记录,即使对于第三方库中的记录器也是如此?

Background: I would like to use java.util.logging in a GlassFish v3 web application. 背景:我想在GlassFish v3 Web应用程序中使用java.util.logging。 However, a third party library in this web app uses Log4J logging and Apache Commons Logging. 但是,此Web应用程序中的第三方库使用Log4J日志记录和Apache Commons Logging。 To save resources, this logging should be minimized or switched off. 为了节省资源,应该最小化或关闭此日志记录。

Edit your log4j configuration and set the logging level to ERROR or FATAL 编辑log4j配置并将日志记录级别设置为ERROR或FATAL

Example for Hibernate: Hibernate的示例:

log4j.logger.org.hibernate=ERROR

This will dwarf the logging output to almost zero, leaving only critical error messages. 这会使日志记录输出几乎为零,只留下严重的错误消息。

you can just raise the log threshold by package for the external libraries. 您可以通过外部库的包提高日志阈值。 I don't know about turning it off. 我不知道要把它关掉。

Have a look at http://www.slf4j.org/ 看看http://www.slf4j.org/

It provides versions of log4j and commons logging libraries that route all the messages to a logging implementation of your choice. 它提供了log4j和commons日志记录库的版本,可以将所有消息路由到您选择的日志记录实现。

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

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