错误在 tomcat 上部署期间找不到关键 log4j.appender.error 的值 [英] ERROR Could not find value for key log4j.appender.error during deploying on tomcat

查看:97
本文介绍了错误在 tomcat 上部署期间找不到关键 log4j.appender.error 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我右键单击服务器并在服务器上运行,我的代码工作正常,但是当我尝试在 tomcat 上部署它并尝试运行它时,它给了我以下错误

my code is working fine if i right click on server and run as run on server , but when i try to deploy it on tomcat and try to run it it is giving me below error

log4j.properties 文件:

log4j.properties file:

log4j.logger.Controller = INFO,error,stdout
log4j.logger.Client = INFO,error,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

错误:

log4j:ERROR Could not find value for key log4j.appender.error
log4j:ERROR Could not instantiate appender named "error".
log4j:ERROR Could not find value for key log4j.appender.error
log4j:ERROR Could not instantiate appender named "error".
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

pom.xml :

<groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.5</version>
        </dependency>
<dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.3</version>
        </dependency>
<dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

推荐答案

问题出在这两行:

log4j.logger.Controller = INFO,error,stdout
log4j.logger.Client = INFO,error,stdout

您只能指定一个记录器级别作为第一个参数(在本例中为 INFO),然后接下来的两个参数将被视为用于该记录器的附加程序名称(在本例中为 error 和 stdout).因为不存在名为 error 的 appender,所以您会收到您报告的错误.

You can only specify one logger level as the first argument (in this case INFO), and then the next two arguments are going to be considered the appender names to use for that logger (in this case error and stdout). Because no appender named error exists, you are getting the errors you've reported.

看看这个(https://logging.apache.org/log4j/1.2/manual.html) 显示了将记录器分配给两个看起来很像您的代码的不同附加程序的示例.希望这将有助于解释为什么 log4j 在您的应用程序中寻找名为 error 的 appender.

Check this out (https://logging.apache.org/log4j/1.2/manual.html) that shows an example of assigning a logger to two different appenders that looks a lot like your code. Hopefully this will help explain why log4j is looking for an appender named error in your application.

这是另一个使用多个 appender 的配置文件.

Here is another configuration file that uses multiple appenders.

log4j.rootLogger=调试、标准输出、R

log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppenderlog4j.appender.R.File=example.log

log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log

log4j.appender.R.MaxFileSize=100KB

log4j.appender.R.MaxFileSize=100KB

log4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

这篇关于错误在 tomcat 上部署期间找不到关键 log4j.appender.error 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆