How to enable Logger.debug() in Log4j

前端 未结 8 1907
谎友^
谎友^ 2020-12-07 18:53

While trying to execute the following lines only the last two statements are displayed(\"Here is some ERROR\" and \"Here is some FATAL\") and the first three statements are

8条回答
  •  天命终不由人
    2020-12-07 19:14

    Here's a quick one-line hack that I occasionally use to temporarily turn on log4j debug logging in a JUnit test:

    Logger.getRootLogger().setLevel(Level.DEBUG);
    

    or if you want to avoid adding imports:

    org.apache.log4j.Logger.getRootLogger().setLevel(
          org.apache.log4j.Level.DEBUG);
    

    Note: this hack doesn't work in log4j2 because setLevel has been removed from the API, and there doesn't appear to be equivalent functionality.

提交回复
热议问题