如何使用 log4j 禁用类的调试日志记录?

发布于 2024-08-19 04:15:27 字数 277 浏览 0 评论 0原文

在我的 log4j.xml 中,我有

<logger name="java.sql">
   <level value="DEBUG" />
</logger>

但是使用它,它还可以启用接口 Resultset 的日志记录。如果我想禁用此接口的日志记录,但仍希望对 statementpreparedstatement 等进行调试日志记录...我该怎么做?

In my log4j.xml, i am having

<logger name="java.sql">
   <level value="DEBUG" />
</logger>

But using this, it also enables the logging for the interface Resultset. If i want to disable the logging for this interface but still want to have the debug logging for statement, preparedstatement, etc... How can i do this?

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

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

发布评论

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

评论(2

昵称有卵用 2024-08-26 04:15:27

Log4j 不允许您根据类或包名称本身来控制日志记录。相反,log4j(和类似的 Java 记录器)的日志记录控制的粒度是由应用程序使用的记录器名称确定的。如果您的 JDBC 驱动程序对于语句、准备好的语句、结果集等有不同的记录器,那就没问题。但是,如果它使用单个记录器进行所有日志记录,您将需要诉诸某种过滤。

有关更多信息,此页面有一个关于在 XML 配置文件中配置过滤器的部分,并且 Filter javadoc 列出了可用(标准)过滤器类别。例如,您可以根据日志记录事件的消息是否与给定字符串匹配进行过滤。

话虽如此,过滤方法会很麻烦,特别是如果有很多不同的消息需要过滤进/出的话。

Log4j does not allow you to control logging based on class or package names per se. Rather, the granularity of logging control with log4j (and similar Java loggers) is determined by the logger names used by the application. If your JDBC driver has different loggers for statements, prepared statements, resultsets and so on, you are fine. However, if it uses a single logger for all of its logging, you would need to resort to some kind of filtering.

For more information, this page has a section on configuring filters in an XML Configuration file, and the Filter javadoc lists the available (standard) filter classes. For example, you can filter based on whether a logging event's message matches a given string.

Having said that, the filtering approach will be cumbersome, especially if there are lots of different messages to be filtered in / out.

傲娇萝莉攻 2024-08-26 04:15:27

您可以为每个类或包使用单独的记录器,但这取决于这些类如何创建自己的记录器。

尽管如此,您最好关注供应商对这些类的实现,而不是关注接口。

You can use individual loggers for each of those classes or packages, but it depends how those classes created there own loggers.

Although, you are better of focusing on the vendor's implementation of those classes instead of focusing on the interfaces.

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