How to enable Logger.debug() in Log4j

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

    This is happening due to the fact that the logging level of your logger is set to 'error' - therefore you will only see error messages or above this level in terms of severity so this is why you also see the 'fatal' message.

    If you set the logging level to 'debug' on your logger in your log4j.xml you should see all messages.

    Have a look at the log4j introduction for explaination.

    0 讨论(0)
  • 2020-12-07 19:30

    Put a file named log4j.xml into your classpath. Contents are e.g.

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    
        <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %t %c{1}:%L - %m%n"/>
            </layout>
        </appender>
    
        <root>
            <level value="debug"/>
            <appender-ref ref="stdout"/>
        </root>
    
    </log4j:configuration>
    
    0 讨论(0)
提交回复
热议问题