在本地服务器中找不到用于记录器的附加程序,但相同的应用程序在生产服务器中运行良好 - log4j

No appenders could be found for logger in local server but same application works fine in Production server- log4j

我们有两台服务器。一个用于 QA,另一个用于生产服务器(托管在 AWS 上)。我在这两种环境中都使用了 "apache-tomcat-8.5.16" 服务器。我们开发了 Spring 启动应用程序,并且 Log4j 配置对于部署在两台服务器上的应用程序是相同的。

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

然而,在本地服务器(用于 QA)中,我们收到错误 "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 配置。

<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" 文件中的配置在两个服务器中也是相同的。

在生产环境中如何获取日志? 当两个 tomcat 服务器版本相同并且相同 war 部署在具有相同配置设置的服务器上时,还有什么不同?

谢谢。

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

谢谢。

这是推荐的备选解决方案。 等了一个星期后,我想,我为什么要担心已经达到生命终点的框架。我升级到 log4j2 并在 class 路径中提供了 log4j2.xml 文件(在我的例子中,/src/main/resources,在 STS-Spring 工具套件中工作,Spring 应用程序。 ).

然而,这种奇怪行为的真正原因仍然未知。

下面是 pom.xml 文件,仅针对冗长的 log4j2 依赖性量身定制。

    <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>

您需要在此行中提供正确的包名称或 class 名称

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

如果有人能找到真正的原因,我们将很高兴。

谢谢。