What is the significance of log4j.rootLogger property in log4j.properties file? What happens if i don't use this property?

后端 未结 3 1054
难免孤独
难免孤独 2020-12-04 12:58

What is the significance of log4j.rootLogger property in log4j.properties file? What happens if I don\'t use this property?

Example

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 13:36

    To answer

    What happens if I don't use this property?

    If you don't set the rootLogger to a level and an appender, you will get a warning.

    For example, if you omit or comment out the line log4j.rootLogger=DEBUG, stdout, i.e. say your log4j.properties file contains only the rootlogger and no additional loggers, here the root logger being commented out:

    #log4j.rootLogger=DEBUG, stdout
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
    

    You will get something like the following output:

    log4j:WARN No appenders could be found for logger (log4jtests.Log4jHelloWorld).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    

提交回复
热议问题