How to enable Logger.debug() in Log4j

前端 未结 8 1934
谎友^
谎友^ 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:12

    You probably have a log4j.properties file somewhere in the project. In that file you can configure which level of debug output you want. See this example:

    log4j.rootLogger=info, console
    
    log4j.appender.console=org.apache.log4j.ConsoleAppender
    log4j.appender.console.layout=org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
    
    log4j.logger.com.example=debug
    

    The first line sets the log level for the root logger to "info", i.e. only info, warn, error and fatal will be printed to the console (which is the appender defined a little below that).

    The last line sets the logger for com.example.* (if you get your loggers via LogFactory.getLogger(getClass())) will be at debug level, i.e. debug will also be printed.

提交回复
热议问题