The Java Maven project introduced slf4j-log4j12, and an error log4j: WARN No appenders could be found for logger was reported during startup

The Java Maven project introduced slf4j-log4j12, and an error log4j: WARN No appenders could be found for logger was reported during startup

1. Error phenomenon

In the resource directory resources in the maven project, the log4j.properties log property file is added. During the test, the main method did not print the log information, and an error was reported:

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

2. The reason for the error

After checking, the log4j.properties property file is indeed in the classes directory after compilation, so the problem of the wrong location of the file is excluded; therefore, the locking may be a factor of the file content, so replace it with the following content, I did not expect it is really caused by property writing errors .

## 输出到控制台
log4j.rootLogger=DEBUG, stdout
## 指定那些包适用debug日志
1og4j.logger.cn.sccdlg=DEBUG

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{
    
    yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n

Postscript :
Warn all technical friends to use Ctrl + Cit carefully . If the configuration is not available due to spelling errors of this kind of word, it can be avoided. Take this as a warning. Of course, the big guys who are familiar with the configuration depend on your preferences.

Guess you like

Origin blog.csdn.net/rao991207823/article/details/113486396