STUDY/Spring
Spring Boot | logback.xml 파일 경로 설정
개미606
2021. 4. 22. 17:25
스프링 프로필을 이용하는 방법과 설정 파일을 이용하는 방법이 있다.
logback.xml? logback-spring.xml?
스프링에서는 logback-spring.xml
로 작성할 것을 권장한다. (특히 커스텀 할 경우)
Spring Profiles를 이용하는 방법
<springProfile>
태그를 이용해 프로필마다 설정을 달리할 수 있다.
아래처럼 설정하면 되는데, <springProfile>
태그 안에 <root>
태그를 넣어 설정해주면 된다.
<springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev | staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
<springProfile name="!production">
<!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>
설정파일(properties / yml)을 이용하는 방법
설정파일에 경로를 미리 지정해두어 해당 값을 <springProperty>
태그를 이용해 불러오는 방법이다.
나는 이 방법을 사용했다. 지정한 활성 프로필에 등록된 경로를 가져온다.
사용방법은 아래와 같다!
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
<remoteHost>${fluentHost}</remoteHost>
...
</appender>