调整apache commons日志记录的日志级别? [英] Adjust Logging level for apache commons logging?

查看:1013
本文介绍了调整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日志记录的日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆