본문 바로가기

JAVA/Error

[Error] log4j2 - ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.

 

 

https://devel-log.tistory.com/27

 

[Error] tomcat server , log4j error - java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

1. 멀쩡하게 하다가 갑자기 에러 발생. log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system pr..

devel-log.tistory.com

 

직전 에러 때문에 log4j2를 추가하였는데,

실행하고 보니 에러 발생.

 

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/chw/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/assignment00/WEB-INF/lib/log4j-slf4j-impl-2.9.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/chw/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/assignment00/WEB-INF/lib/slf4j-log4j12-1.6.6.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]
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.

 

플러그인 라이브러리 중에 동일한 클래스 중복이 발생한 문제라고 함.

 

해결 1.

 

Help > Eclipse marketplace > Installed


첫번째 목록 아이템의 우측 하단의 [Change]버튼을 클릭
[Change]버튼이 안 보이는 경우 우측하단 적당한 영역을 클릭

m2e - slf4j over logback logging (Optinal)을 선택 해제
[Confirm]​​​​​​​ 클릭 Uninstall 진행.

 

 

해결 2.

 

log4j 중복 선언 에러 / 중복된 라이브러리 제거

 

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${org.slf4j-version}</version>
			<!-- <scope>runtime</scope> -->
		</dependency>
		
		<!--  log4j2  -->
		<dependency>
		    <groupId>org.apache.logging.log4j</groupId>
		    <artifactId>log4j-api</artifactId>
		    <version>2.9.0</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.logging.log4j</groupId>
		    <artifactId>log4j-core</artifactId>
		    <version>2.9.0</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.logging.log4j</groupId>
		    <artifactId>log4j-slf4j-impl</artifactId>
		    <version>2.9.0</version>
		</dependency>

 

나 같은 경우는 

에러 라인에 'log4j-slf4j-impl' 와 'slf4j-log4j12' 가 중복이라고 함.

slf4j-log4j12 제거

 

log4j2.java 생성

package com.assignment.exception;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Log4j2 {
    
    private Logger logger = LogManager.getLogger(Log4j2.class);
    
    public void printLog() {
        logger.debug("[debug] log!");
        logger.info("[info] log!");
        logger.warn("[warn] log!");
        logger.error("[error] log!");
    }
}

 

사용하는 Class에 logger 변수 선언.

private Logger logger = LogManager.getLogger(Log4j2.class);

logger.info("blah blah");

 

남은 에러 

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

 

Maven clean > install 

- Maven Dependensies 에 log4j2 관련한 .jar 파일이 포함되지 않아 생기는 오류.

라고 하여 다 뒤졌으나 해결 안됨.

 

+

src/main/resources/properties 경로에 있던

jdbc.properties
log4j2.xml
log4dbc.log4j2.properties 를

src/main/webapp/WEB-INF/classes 에 이동시킴.

 

결국엔 경로 문제였고.. 굉장히 허탈하지만 해결해서 다행이라고 생각 한다.

WEB-INF 디렉토리 위치에 없으면 발생하는 것 같음.