调整apache commons日志记录的日志级别?

编程入门 行业动态 更新时间:2024-10-25 12:22:29
本文介绍了调整apache commons日志记录的日志级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简单的控制台应用程序,它使用apache的PDFBox库,后者又使用公共日志记录。我在我的控制台中收到了很多垃圾邮件我想抑制:

I have a simple console app which uses apache's PDFBox library, which in turn uses commons logging. I'm getting a lot of junk messages in my console which I'd like to suppress:

2011年2月15日3:56:下午40点org.apache.pdfbox.util.PDFStreamEngine processOperator INFO:不支持/禁用操作:EI

Feb 15, 2011 3:56:40 PM org.apache.pdfbox.util.PDFStreamEngine processOperator INFO: unsupported/disabled operation: EI

在我的代码中,我试图重置日志级别无济于事:

In my code, I've tried to reset the log levels to no avail:

Logger.getLogger("org.apache.pdfbox.util.PDFStreamEngine").setLevel(Level.OFF); Logger.getLogger("org.apache.pdfbox.util").setLevel(Level.OFF); Logger.getLogger("org.apache.pdfbox").setLevel(Level.OFF);

尽管有这些设置,但消息仍显示在控制台上。从Commons日志记录中检索日志对象也没有帮助,因为它似乎没有办法设置级别。

Despite these settings, the messages are still showing up on the console. Retrieving the log object from Commons logging doesn't help either, since it doesn't seem to have a way to set the level.

有没有办法来抑制这些消息以编程方式?或者我是否需要添加配置文件?

Is there a way to suppress these messages programmatically? Or do I need to add a config file?

推荐答案

Commons-logging只是一个logging-facade,意味着它没有提供实际将logdata写入例如磁盘的代码。您需要更改的是实际日志记录实现的配置(例如 logback , log4j , sl4fj 等)。如果没有找到这样的库,则默认为 java.util.logging 。

Commons-logging is only a logging-facade, meaning it doesn't provide the code which actually writes the logdata to e.g., disk. What you need to change is the configuration for the actual logging implementation (such as logback, log4j, sl4fj etc). If no such library is found it defaults to java.util.logging.

我建议在类路径中输入eg, log4j 并在类路径中添加 log4j.xml 配置文件。在这种情况下,类路径中仅存在 log4j 足以初始化它。 Log4j也可以以编程方式配置。

I would recommend putting e.g., log4j in the classpath and add a log4j.xml configuration file in your classpath. The mere presence of log4j in the classpath is in this case enough to initialize it. Log4j can also be configured programmatically.

更多推荐

调整apache commons日志记录的日志级别?

本文发布于:2023-11-24 04:16:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日志   级别   apache   commons

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!