About the console output warning Log4j:warn No appenders could be found for logger

Source: Internet
Author: User

A warning appears when you create a new STRUTS2 project

Log4j:warn No appenders could be found for logger

And searched the solution on the Internet.

Turn from: Favorite NBA


Under SRC, create a new file named Log4j.properties content as follows:

# Configure logging for testing:optionally with log file
Log4j.rootlogger=warn, stdout
# Log4j.rootlogger=warn, stdout, logfile

Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=%d%p [%c]-%m%n

Log4j.appender.logfile=org.apache.log4j.fileappender
Log4j.appender.logfile.file=target/spring.log
Log4j.appender.logfile.layout=org.apache.log4j.patternlayout
log4j.appender.logfile.layout.conversionpattern=%d%p [%c]-%m%n

Or

# Configure logging for testing:optionally with log file
#可以设置级别: Debug>info>error
#debug: Can be explicitly debug, Info,error
#info: You can explicitly info,error
#error: You can explicitly error

Log4j.rootlogger=debug,appender1
#log4j. Rootlogger=info,appender1
#log4j. Rootlogger=error,appender1

# output to console
log4j.appender.appender1= Org.apache.log4j.ConsoleAppender
#样式为TTCCLayout
log4j.appender.appender1.layout= Org.apache.log4j.TTCCLayout
===============================
Re-released, OK, no prompt. Once you have added this profile, the warnings on the program run will disappear. Especially in the web layer development, only when the file is added to see the spring background complete error message. When developing the spring consolidation application
, there are often people who encounter a 404 error but do not see any error messages, and then you need to check if a
file is present.

When developing related projects in Eclipse, you often see the following information in the console:
Log4j:warn No appenders could is found for logger
Log4j:warn Initialize the log4j system properly.

The output information here is not an error message but only a warning message, because log4j cannot output the log, log4j is a log input package. You can extract a compressed package such as struts or hibernate, have a log4j.properties file inside it, copy it to the Project Src folder, or put Log4j.properties in the \web-inf\classes folder.

===================================
WARN No Appenders could is found for logger solution

These days to do an SSH project, Tomcat starts with the following issues:
Log4j:warn No Appenders could is found for logger (org.springframework.web.context.ContextLoader).
Log4j:warn Initialize the log4j system properly.

Check on the Internet, much is said to change the Contextloaderlistener to Springcontextservlet, but I changed the useless. Later on an English website to see a post on the same issue, he changed:

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j.properties</param-value>
</context-param>

······

<!--definition log4j listener--
<listener>
<listener-class>
Org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>

This changed the problem to solve, no need to modify the Contextloaderlistener.

About the console output warning Log4j:warn No appenders could be found for logger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.