Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 调试日志记录在特定处理程序上不起作用_Java_Logging_Apache Commons - Fatal编程技术网

Java 调试日志记录在特定处理程序上不起作用

Java 调试日志记录在特定处理程序上不起作用,java,logging,apache-commons,Java,Logging,Apache Commons,我将JDK14Logger实现用于apache commons loggings框架。调试日志不会出现,只有在我将根记录器设置为“精细”时才会出现。我的理解是,设置为特定处理程序的日志级别应该覆盖根记录器的日志级别。然而,这并没有发生 # The following creates the console handler handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler # Set the defa

我将JDK14Logger实现用于apache commons loggings框架。调试日志不会出现,只有在我将根记录器设置为“精细”时才会出现。我的理解是,设置为特定处理程序的日志级别应该覆盖根记录器的日志级别。然而,这并没有发生

# 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");

}

}

默认情况下,所有JDK记录器都会将日志记录发布到根记录器的处理程序。ConsoleHandler的默认级别为

我的理解是,设置为特定处理程序的日志级别应该覆盖根记录器的日志级别。然而,这并没有发生

没有,也不是

调试日志不会出现,只有在我将根记录器设置为“精细”时才会出现

输出被发布到处理程序。不出现表示未附加处理程序、未将级别设置为预期级别,或者处理程序已附加到不在发布路径上的子记录器

修改链接答案中的DebugLogging类,以包含您的配置和执行日志记录的apache commons代码。不要删除JDK日志代码。该代码的输出将引导您找到问题所在