【发布时间】:2020-05-22 04:32:34
【问题描述】:
我正在使用 JDK14Logger 实现 apache commons-loggings 框架。调试日志没有出现,它们仅在我将根记录器设置为 FINE 时出现。我的理解是,设置为特定处理程序的日志级别应该覆盖根记录器的日志级别。然而,这并没有发生。
# The following creates the console handler
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Set the default logging level for the root logger
.level=FINE
# Set the default logging level
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.FileHandler.level=FINEST
# log level for the "com.rst.example" package
# Set the default formatter
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
# Specify the location and name of the log file
java.util.logging.FileHandler.pattern=D:/test.log
测试类:
public class Test {
private Log logger = LogFactory.getLog(Test.class.getName());
static {
System.getProperties().setProperty("java.util.logging.config.file","log-config.properties");
}
public static void main(String[] args) {
//-Djava.util.logging.config.file=src/main/resources/log-config.properties
Test test = new Test();
test.logger.info("info from main");
test.logger.error("error from main");
test.logger.fatal("fatal from main");
System.out.println("is dubug enabled? :" + test.logger.isDebugEnabled());
test.logger.debug("debug from main");
}
}
【问题讨论】:
标签: java logging apache-commons