2014-10-24 1 views
4

Log4J2와 함께 작동하도록 SLF4J를 설정하려고합니다.Log4j2가 설정 파일을 찾을 수 없습니다.

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

그리고 내 log4j2.xml 파일 : 나는 간단한 테스트를위한 설정을 사용하고

<properties> 
    <log4j.version>2.1</log4j.version> 
</properties> 

<!-- Logging --> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.7.7</version> 
</dependency> 
<dependency> 
    <groupId>org.apache.logging.log4j</groupId> 
    <artifactId>log4j-api</artifactId> 
    <version>${log4j.version}</version> 
</dependency> 
<dependency> 
    <groupId>org.apache.logging.log4j</groupId> 
    <artifactId>log4j-core</artifactId> 
    <version>${log4j.version}</version> 
</dependency> 
<dependency> 
    <groupId>org.apache.logging.log4j</groupId> 
    <artifactId>log4j-slf4j-impl</artifactId> 
    <version>${log4j.version}</version> 
</dependency> 

: 여기

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. 

내 POM 종속성입니다 :하지만이 오류가 계속 src/main/resources에 있습니다.

enter image description here

enter image description here

나는 확인 다른 모르겠어요. 또한 xml 파일을/src 디렉토리로 옮겨 보았지만 도움이되지 않았습니다. 내가 뭘 놓치고 있니?

답변

1

버전 2.1의 버그 인 것으로 보입니다. Log4j2를 2.0.1 버전으로 롤백했는데 모든 것이 잘 작동합니다.

+0

버그로 연결 하시겠습니까? – Sid

2

배포 할 서버를 지정하지 않고 Wildfly 8.1에서 웹 응용 프로그램을 배포하려고 할 때 동일한 문제가 발생하여 src/main/resources 폴더에 log4j2.xml이 있습니다.

this thread에 log4j2 버그가 아니고 JBoss/Wildfly 코드의 버그라고 지적했습니다. 스레드에서 하산 Kalaldeh을 인용

는 :

I found what is the problem, if you extract log4j-web-2.1.jar and open servlet container Initializer service in file : log4j-web-2.1\META-INF\services\javax.servlet.ServletContainerInitializer you will find this: javax.servlet.ServletContainerInitializer

# 
# Licensed to the Apache Software Foundation (ASF) under one or more 
# contributor license agreements. See the NOTICE file distributed with 
# this work for additional information regarding copyright ownership. 
# The ASF licenses this file to You under the Apache license, Version 2.0 
# (the "License"); you may not use this file except in compliance with 
# the License. You may obtain a copy of the License at 
# 
#  http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the license for the specific language governing permissions and 
# limitations under the license. 
# org.apache.logging.log4j.web.Log4jServletContainerInitializer 

I've been reading JBoss deployer source code and I found it always read first row of service file // this line from ServletContainerInitializerDeploymentProcessor.loadSci() String servletContainerInitializerClassName = reader.readLine();

so when I manually edit the service file and just keep the last line (org.apache.logging.log4j.web.Log4jServletContainerInitializer) it works fine now

anycase에서, 나는 2.0.2 내 log4j2 버전을 되돌릴 않았고 그것은뿐만 아니라 일하고있어.