简体   繁体   English

Log4j 警告:即使有附加程序,也找不到附加程序

[英]Log4j warning: no appenders found even if it is there

My project is in spring and for log configuration, I'm using log4j.我的项目是在春季和日志配置,我使用 log4j。 The issue that I'm facing is that, I'm getting the following warning while starting the wildfly in the site server我面临的问题是,在站点服务器中启动 Wildfly 时收到以下警告

18:06:42,630 ERROR [stderr] (MSC service thread 1-7) log4j:WARN No appenders could be found for logger (org.jboss.logging).
18:06:42,630 ERROR [stderr] (MSC service thread 1-7) log4j:WARN Please initialize the log4j system properly.
18:06:42,630 ERROR [stderr] (MSC service thread 1-7) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

But the log4j2.xml file is there inside project.war/WEB-INF/classes/ directory.但是 log4j2.xml 文件在project.war/WEB-INF/classes/目录中。 I couldn't simulate this problem in my local or in our servers because the same war is working fine without any problems.我无法在我的本地或我们的服务器中模拟这个问题,因为同样的战争运行良好,没有任何问题。

sharing the java version of both places.共享两个地方的java版本。

local:当地的:

openjdk version "1.8.0_222-ea"
OpenJDK Runtime Environment (build 1.8.0_222-ea-b03)
OpenJDK 64-Bit Server VM (build 25.222-b03, mixed mode)

Site:地点:

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

Sharing the log4j2.xml for your reference.分享log4j2.xml供大家参考。

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60">
  <Properties>
    <Property name="log-path">D:\Server\apache-tomcat-9.0.12\logs\</Property>
    <Property name="archive">${log-path}\\archive\\</Property>
  </Properties>
  <Appenders>
    <Console name="Console-Appender" target="SYSTEM_OUT">
        <PatternLayout>
            <pattern>
                [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} (%F:%L) %X{TransactionId} - %msg%n
            </pattern>>
        </PatternLayout>
    </Console>
    <File name="File-Appender" fileName="${log-path}/data.log" >
        <PatternLayout>
            <pattern>
                [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} (%F:%L) %X{TransactionId}  - %msg%n
            </pattern>
        </PatternLayout>
    </File>
        <RollingFile name="RollingFile-Appender"
                 fileName="${log-path}/data_back.log"
                 filePattern="${archive}/data.log.%d{yyyy-MM-dd-hh-mm}.gz">
        <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] (%F:%L) %X{TransactionId} - %msg%n"/>
            <Policies>
                 <TimeBasedTriggeringPolicy/>
                 <SizeBasedTriggeringPolicy size="30 MB"/>
            </Policies>
                 <DefaultRolloverStrategy max="30"/>
    </RollingFile>
</Appenders>
<Loggers>

       <Logger name="com.project" level="debug" additivity="false">
           <AppenderRef ref="File-Appender" level="debug"/>
           <AppenderRef ref="RollingFile-Appender" level="debug"/>
           <AppenderRef ref="Console-Appender" level="debug"/>
       </Logger> 
       <Logger name="com.project" level="debug" additivity="false">
           <AppenderRef ref="File-Appender" level="debug"/>
           <AppenderRef ref="RollingFile-Appender" level="debug"/>
           <AppenderRef ref="Console-Appender" level="debug"/>
       </Logger> 
        <Logger name="org.springframework" level="info" additivity="false">
           <AppenderRef ref="File-Appender" level="debug"/>
           <AppenderRef ref="RollingFile-Appender" level="debug"/>
           <AppenderRef ref="Console-Appender" level="debug"/>
       </Logger> 
       <Logger name="org.hibernate" level="info" additivity="false">
           <AppenderRef ref="File-Appender" level="debug"/>
           <AppenderRef ref="RollingFile-Appender" level="debug"/>
           <AppenderRef ref="Console-Appender" level="debug"/>
       </Logger>

    <Root level="info">
        <AppenderRef ref="Console-Appender"/>
    </Root>
 </Loggers>
</Configuration>

Please help me sort this out.请帮我解决这个问题。 Thanks谢谢

I am updating this answer based on your comment below.我正在根据您在下面的评论更新此答案。

The log4j:warn messages are coming from Log4j 1.x. log4j:warn 消息来自 Log4j 1.x。 It is telling you that it cannot find any configuration.它告诉您它找不到任何配置。 The configuration you show is for Log4j 2.您显示的配置适用于 Log4j 2。

If you intend to use both Log4j 1 and Log4j 2 then you must provide a valid configuration for both.如果您打算同时使用 Log4j 1 和 Log4j 2,那么您必须为两者提供有效的配置。 Do NOT try to log to the same files.不要尝试登录到相同的文件。 In this scenario you should not have log4j-1.2-api.2.10.jar as that replaces log4j-1.2.17.jar.在这种情况下,您不应该使用 log4j-1.2-api.2.10.jar,因为它会替换 log4j-1.2.17.jar。

If you only want to use Log4j 2 then remove the log4j 1.2.17 jar and leave the log4j-1.2-api-2.10.0.jar from Log4j 2. You should also be using log4j-slf4j-impl-2.10.0.jar and not slf4j-log4j12-1.7.25.jar.如果您只想使用 Log4j 2,则删除 log4j 1.2.17 jar 并保留 Log4j 2 中的 log4j-1.2-api-2.10.0.jar。您还应该使用 log4j-slf4j-impl-2.10.0.jar而不是 slf4j-log4j12-1.7.25.jar。 If commons logging is present then you should use log4j-jcl-2.10.0.jar.如果存在公共日志记录,那么您应该使用 log4j-jcl-2.10.0.jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM