헤르메스 LIFE

[Spring Boot] logbak-local 설정 본문

Spring Boot Framework

[Spring Boot] logbak-local 설정

헤르메스의날개 2024. 8. 1. 11:23
728x90

Spring Boot 개발 시 logbak-local 설정이 적용이 안되서 찾아 보니 아래와 같이 설정해야 한다고 합니다.

 

개발환경

Tools : STS 4.22.1.RELEASE

JDK : zulu11.72.19-jdk11.0.23

Framework : Spring Boot 2.7.18

Logging : Logback 1.2.12


`-Dspring.profiles.active=local` 설정 

application.yml

# Spring 설정
spring:
  application: # Application 이름
    name: ezpus
    
  profiles:
    active: local # `-Dspring.profiles.active=local` Default 설정

logging:
  config: classpath:logback-${spring.profiles.active}.xml

 

logback-local.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%-5level %d{yy-MM-dd HH:mm:SSS}[%thread]>>[%30logger.%method:%line] - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="jdbc" level="OFF"/>
    <logger name="jdbc.sqlonly" level="OFF"/>
    <logger name="jdbc.sqltiming" level="OFF"/>
    <logger name="jdbc.audit" level="OFF"/>
    <logger name="jdbc.resultset" level="OFF"/>
    <logger name="jdbc.resultsettable" level="OFF"/>
    <logger name="jdbc.connection" level="INFO"/>

    <logger name="cspi.ezpus" level="debug" additivity="false">
        <!-- ref="appender name 지정" -->
        <appender-ref ref="STDOUT" />
        <!-- <appender-ref ref="ROLLING-FILE" /> -->
    </logger>
    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>

</configuration>

logback-prod.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%-5level %d{yy-MM-dd HH:mm:SSS}[%thread]>>[%30logger.%method:%line] - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="jdbc" level="OFF"/>
    <logger name="jdbc.sqlonly" level="OFF"/>
    <logger name="jdbc.sqltiming" level="OFF"/>
    <logger name="jdbc.audit" level="OFF"/>
    <logger name="jdbc.resultset" level="OFF"/>
    <logger name="jdbc.resultsettable" level="OFF"/>
    <logger name="jdbc.connection" level="INFO"/>

    <root level="WARN">
        <appender-ref ref="STDOUT" />
    </root>

</configuration>

https://dadadamarine.github.io/java/spring/2019/05/01/spring-logging-xml.html

 

Push Stone's blog

테스트는, 자신을 작성한 만큼만 기능을 보장해준다. 그러니까 테스트를 작성하는 일은 각 기능에 대한 보증서를 모으는 작업이다.

dadadamarine.github.io

 

728x90