2017-10-04 4 views
0

내 스프링 응용 프로그램에서 logback 대신 log4j2를 사용하려고하는데 오류가 계속 발생합니다. 내가 봄 부팅 응용 프로그램을 실행할 때 그것은 내가 여러 블로그를 따라하지만봄 부팅 응용 프로그램에서 log4j2가 작동하지 않습니다.

SLF4J: Class path contains multiple SLF4J bindings. 
SLF4J: Found binding in [jar:file:/Users/asd.asd/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.6.2/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: Found binding in [jar:file:/Users/asd.asd/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. 
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] 
[WARNING] 
java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:483) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/Users/karan.shah/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.6.2/log4j-slf4j-impl-2.6.2.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.apache.logging.slf4j.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext 
    at org.springframework.util.Assert.isInstanceOf(Assert.java:346) 
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:221) 
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLogger(LogbackLoggingSystem.java:213) 
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98) 
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartedEvent(LoggingApplicationListener.java:222) 

오류를 발생

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration monitorInterval="60"> 
    <Properties> 
     <Property name="path">logs</Property> 
    </Properties> 
    <Appenders> 
     <Console name="Console-Appender" target="SYSTEM_OUT"> 
      <PatternLayout> 
       <pattern> 
        [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n 
       </pattern>> 
      </PatternLayout> 
     </Console> 
     <File name="App-Appender" fileName="${path}/app_log.log" > 
      <PatternLayout> 
       <pattern> 
        [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n 
       </pattern> 
      </PatternLayout> 
     </File> 
     <File name="SpringBoot-Appender" fileName="${path}/springboot_log.log" > 
      <PatternLayout> 
       <pattern> 
        [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n 
       </pattern> 
      </PatternLayout> 
     </File> 
    </Appenders> 
    <Loggers> 
     <Logger name="master.dt" level="info" additivity="false"> 
      <AppenderRef ref="SpringBoot-Appender"/> 
      <AppenderRef ref="Console-Appender"/> 
     </Logger> 
     <Logger name="master.dt" level="info" additivity="false"> 
      <AppenderRef ref="App-Appender"/> 
      <AppenderRef ref="Console-Appender"/> 
     </Logger> 
     <Root> 
      <AppenderRef ref="Console-Appender"/> 
     </Root> 
    </Loggers> 
</Configuration> 

처럼 POM을 파일

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.7.RELEASE</version> 
    <relativePath /> 
</parent> 

<dependencies> 
    <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-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-log4j2</artifactId> 
    </dependency> 
</dependencies> 

log4j2 XML 파일처럼 보이는 외모 그들 중 누구도 일하고 ​​있지 않습니다. log4j2 작업을 수행하는 올바른 방법은 무엇입니까?

답변

0

slf4j와 jar 충돌이 있습니다. 종속성 트리를보고 어떤 항아리를 제외할지 알아보십시오.

+0

이 질문에 대한 답변을 제공하지 않습니다. 비평하거나 저자의 설명을 요청하려면 게시물 아래에 의견을 남겨 둡니다. - [리뷰에서] (리뷰/저품절 게시물/17521874) –