问题描述
我使用log4j在我的应用程序中记录了一些步骤.为了快速而肮脏,我使用了:
org.apache.log4j.BasicConfigurator.configure();
此输出我的日志在Eclipse控制台中.
我想知道是否以及如何设置高于调试的级别阈值?换句话说,我不想显示调试级别的消息,只需err,警告,信息.
谢谢.
编辑: 我可以使用以下内容吗?
import org.apache.log4j.Logger; import org.apache.log4j.Level; [...] Logger logger = Logger.getLogger(this.class); logger.setLevel(Level.INFO);
推荐答案
我认为最简单的方法是:
Logger.getRootLogger().setLevel(Level.INFO);
其他推荐答案
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
其他推荐答案
假设您在调用任何记录器之前都在调用basic Configurator.configure():
您可以使用这些配置文件中的任何一个更改它而无需重新编译:
log4j.properties
log4j.rootLogger=INFO
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <root> <priority value="INFO"/> </root> </log4j:configuration>
其中之一必须在命令行上.
问题描述
I used log4j to log some steps in my application. To be quick and dirty, I used:
org.apache.log4j.BasicConfigurator.configure();
This output my logs in the Eclipse console.
I want to know if and how to set the level threshold higher than DEBUG? In other word, I do not want to display DEBUG level message, just ERR, WARN, INFO.
Thank you.
EDIT: May I use this following?
import org.apache.log4j.Logger; import org.apache.log4j.Level; [...] Logger logger = Logger.getLogger(this.class); logger.setLevel(Level.INFO);
推荐答案
I think the simplest way would be:
Logger.getRootLogger().setLevel(Level.INFO);
其他推荐答案
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
其他推荐答案
Assuming you are calling BasicConfigurator.configure() before any loggers are called:
You can use either of these config files to change it without recompiling:
log4j.properties
log4j.rootLogger=INFO
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <root> <priority value="INFO"/> </root> </log4j:configuration>
One of these must be on command line.