본문 바로가기
Back-end/JAVA & Spring

★간단한 logback 설정하기

by 꼬바리 2021. 4. 28.

pom.xml 설정

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${version.slf4j}</version>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.7</version>
</dependency>

 

로그 레벨

ERROR, WARN , INFO, DEBUG, TRACE

 

logback 설정파일

일반적으로 logback.xml으로 만들며 src/main/resources/ 아래에 위치시킨다.

 

기본 구조

<configuration>
    <appender> Appender 설정 </appender>
    <logger> Logger 설정 </loggger>
</configuration>

logback.xml

<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="3 seconds">
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <layout>
            <pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
            </pattern>
        </layout>
    </appender>

    <logger name="org.springframework" level="INFO" />

    <root level="TRACE">
        <appender-ref ref="console"/>
    </root>
</configuration>

 

LogTest.java

 

public class LogTest {

    private static final Logger LOG = LoggerFactory.getLogger(LogTest.class);
    @Test
    public void logTest(){
        String id = "corn";

        LOG.trace("trace, id : {}", id);
        LOG.debug("debug, id : {}", id);
        LOG.info("info, id : {}", id);
        LOG.warn("warn, id : {}", id);
        LOG.error("error, id : {}", id);
    }
}

결과

 

728x90
반응형

댓글