26.7 로그백 확장

Spring Boot는 고급 구성을 도울 수있는 Logback에 대한 여러 가지 확장 기능을 포함합니다. logback-spring.xml구성 파일 에서이 확장을 사용할 수 있습니다 .

표준 logback.xml구성 파일이 너무 일찍로드 되었기 때문에 확장을 사용할 수 없습니다. logging.config 속성을 사용하거나 logback-spring.xml을 정의해야합니다.

확장 기능은 Logback의 구성 스캐닝 과 함께 사용할 수 없습니다 . 그렇게하려고하면 구성 파일을 변경하면 다음 중 하나와 유사한 오류가 기록됩니다.

ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]

26.7.1 프로파일 별 설정

<springProfile>태그를 포함하거나 활성화된 스프링의 프로필을 기반으로 구성 섹션을 제외 선택적으로 할 수 있습니다. 프로필 섹션은 <configuration>요소 내 어디에서나 지원됩니다 . 이 name속성을 사용하여 구성을 허용하는 프로필을 지정합니다. <springProfile>태그 (예를 들면 단순한 프로파일 이름을 포함 할 수있는 staging) 또는 프로파일 식. 프로파일 표현식은보다 복잡한 프로파일 로직이 표현되도록합니다 production & (eu-central | eu-west). 자세한 내용 은 참조 가이드 를 확인하십시오. 다음 목록은 세 가지 샘플 프로필을 보여줍니다.

<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>

26.7.2 환경 프로퍼티

<springProperty>태그를 사용하면 EnvironmentLogback 내에서 사용하기 위해 Spring의 속성을 노출 할 수 있습니다 . 이렇게하면 application.propertiesLogback 구성에서 파일의 값에 액세스하려는 경우 유용 할 수 있습니다 . 이 태그는 Logback의 표준 <property>태그 와 비슷한 방식으로 작동합니다 . 그러나 direct를 지정하는 대신 (에서 ) 속성 value을 지정합니다 . 범위가 아닌 어딘가에 속성을 저장해야하는 경우 속성을 사용할 수 있습니다 . 대체 값이 필요한 경우 (속성이에 설정되지 않은 경우 ) 속성을 사용할 수 있습니다 . 다음 예는 Logback에서 사용할 속성을 표시하는 방법을 보여줍니다.sourceEnvironmentlocalscopeEnvironmentdefaultValue

<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>

source는 케밥 케이스(?) 에서 구체화되어야한다. (가령 my.property-name). 그러나 Environment느슨한 규칙을 사용하여 속성을에 추가 할 수 있습니다 .

케밥 케이스 :

  • 하이픈으로 단어를 연결하는 표기법

  • HTML 태그의 id, class 속성으로 흔히 쓰임

Last updated