簡體   English   中英

調試日志不適用於特定的處理程序

[英]Debug logging is not working on specific handler

我正在對 apache commons-loggings 框架使用 JDK14Logger 實現。 調試日志沒有出現,只有當我將根記錄器設置為 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");

}

}

默認情況下,所有 JDK 記錄器都會將日志記錄發布到根記錄器的處理程序。 ConsoleHandler 的默認級別是INFO

我的理解是,設置為特定處理程序的日志級別應該覆蓋根記錄器的日志級別。 然而,這並沒有發生。

它沒有,也不是。 使用 DebugLogging 根據 JDK 日志測試您的配置文件

調試日志沒有出現,只有當我將根記錄器設置為 FINE 時才會出現。

輸出發布到處理程序。 未出現意味着您的處理程序未附加,級別未設置為您期望的級別,或者處理程序附加到不在發布路徑上的子記錄器。

修改鏈接答案中的 DebugLogging 類以包含您的配置和執行日志記錄的 apache-commons 代碼。 不要刪除 JDK 日志記錄代碼。 該代碼的輸出將引導您解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM