Configure log4j in Spring project

xiaoxiao2021-04-04  239

1. Log4j.properties will be tested when using the JUnit local test below:

Log4J: Warn no appenders could be found for logger (org.springframework.beans.factory.access.singletonbeanfactoryLocator) .log4j: warn please initialize the log4j system protralize.

Then we can't see the configuration information of Spring load beans. Add: log4j.properties under the ClassPath path, you can display the loading information of Bean

2. Configuring log4jspring for Spring in web applications is to use a servlet listner. When the Web Container is started, the root's absolute path is written to the system variable, so you can use $ {myAppfuse.root} in the log4j configuration file. Indicates the system variable just set up: log4j.Appender.logfile.file = $ {myappfuse.root} /logs/mylog.log In Web.xml configuration statement is as follows:

WebApprootKey myAppfuse. Root log4jconfiglocation /web-inf/classess/log4j.properties org.springframework.web.util.log4jconfiglistener Configure a Listener, or configuring servlet: log4j org.springframework.web.util.log4jconfigservlet 1 After you have configured, we can find logging files in the current application log directory: MyLog.log property log4jconfigLocation is recommended or set to: /web-inf/classess/log4j.properties, so we don't start web applications Time to do some tests this can correct log information correctly.

转载请注明原文地址:https://www.9cbs.com/read-131965.html

New Post(0)