在本地服务器中找不到记录器的附加程序,但是在生产服务器中相同的应用程序可以正常工作-log4j [英] No appenders could be found for logger in local server but same application works fine in Production server- log4j

查看:85
本文介绍了在本地服务器中找不到记录器的附加程序,但是在生产服务器中相同的应用程序可以正常工作-log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两台服务器.一个用于质量检查,另一个用于生产服务器(托管在AWS上).我在两种环境中都使用过"apache-tomcat-8.5.16"服务器.我们已经开发了Spring boot应用程序,两个服务器中部署的应用程序的Log4j配置都是相同的.

We have two servers. One for QA and another is Production server (hosted on AWS). I have used "apache-tomcat-8.5.16" server in both environment. We have developed Spring boot app and Log4j configuration is same for applications deployed in both servers.

logging.level.net.companyname= DEBUG
logging.level.com.google.api.ads.dfp.lib.client.DfpServiceClient.soapXmlLogger=WARN
logging.level.com.google.api.ads.dfp.lib.client.DfpServiceClient.requestInfoLogger=INFO

但是,在本地服务器(用于质量检查)中,我们收到错误消息"log4j:WARN找不到记录器(org.springframework.web.context.support.StandardServletEnvironment的附加程序).

Yet, in local server (used for QA), we are getting the error "log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment" .

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

但是在生产服务器中,我们可以毫无问题地获取日志. 如果有关系的话,下面是与log4j相关的pom.xml配置.

But in Production server we are getting logs without any problem. If it does matter, below is the pom.xml configuration related to log4j.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
</dependency>

"apache-tomcat-8.5.16/conf/logging.properties"文件中的所有配置在两台服务器中也相同.

Even configurations inside "apache-tomcat-8.5.16/conf/logging.properties" file are also same in both servers.

如何在生产环境中获取日志? 如果两个tomcat服务器版本相同,并且使用相同的配置设置在两个服务器上部署了相同的战争,还会有什么不同?

How to get logs as we are getting in Production environment? What else would make difference when both tomcat server versions are same and same war is deployed on both of them with same configuration settings?

谢谢.

更新: 我从服务器上下载了war文件到本地进行测试,即使在那里,log4j也能正常工作.我还需要检查什么?

Update: I downloaded the war file to local from server for testing and even there, log4j is working fine. What else do I need to check?

谢谢.

推荐答案

这是另一种推荐的解决方案. 在等待了一周之后,我想,为什么要为即将到期的框架感到担忧.我升级到log4j2并在类路径中提供了log4j2.xml文件(在我的情况下为/src/main/resources,在STS-Spring Tool Suite Spring应用程序中工作.)

This is an alternative and recommended solution. After waiting for a week, I thought, why should I worry on framework that has reached it's end of life. I upgraded to log4j2 and provided log4j2.xml file in the classpath (in my case, /src/main/resources, working in STS-Spring Tool Suite, Spring application.).

但是,这种奇怪行为的实际原因仍然未知.

However the actual reason for this weird behavior is still unknown.

下面是pom.xml文件,它仅为冗长而专门定制了log4j2依赖项.

Below is the pom.xml file tailored only log4j2 dependency for verbosity.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout
                pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - ***CustomLog*** %msg ***/CustomLog***%n" />
        </Console>

        <File name="traceLoggerFile" fileName="logs/trace.log">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
        </File>
        <File name="debugLoggerFile" fileName="logs/debug.log">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
        </File>
        <File name="infoLoggerFile" fileName="logs/info.log">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
        </File>
        <File name="errorLoggerFile" fileName="logs/errors.log">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
        </File>
    </Appenders>

    <Loggers>
        <Logger name="com.packageName" level="TRACE">
            <AppenderRef ref="traceLoggerFile" level="TRACE" />
            <AppenderRef ref="debugLoggerFile" level="DEBUG" />
            <AppenderRef ref="infoLoggerFile" level="INFO" />
            <AppenderRef ref="errorLoggerFile" level="ERROR" />
        </Logger>
        <Root level="DEBUG">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

您需要在此行中输入正确的软件包名称或类名称

You need to give proper package name or class name in this line

<Logger name="com.packageName" level="TRACE">

如果任何人都能找到真正的原因,就会很高兴.

Will be happy if anyone can find the actual reason.

谢谢.

这篇关于在本地服务器中找不到记录器的附加程序,但是在生产服务器中相同的应用程序可以正常工作-log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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