> For the complete documentation index, see [llms.txt](https://wannaqueen.gitbook.io/spring5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wannaqueen.gitbook.io/spring5/spring-boot/undefined-1/26.-by-ks/26.7.md).

# 26.7 로그백 확장

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

| ![\[노트\]](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/images/note.png)                  |
| ---------------------------------------------------------------------------------------------------------------- |
| 표준 `logback.xml`구성 파일이 너무 일찍로드 되었기 때문에 확장을 사용할 수 없습니다. **logging.config 속성을 사용하거나 logback-spring.xml을 정의해야합니다.** |

| ![\[경고\]](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/images/warning.png)                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------- |
| 확장 기능은 Logback의 [구성 스캐닝](https://logback.qos.ch/manual/configuration.html#autoScan) 과 함께 사용할 수 없습니다 . 그렇게하려고하면 구성 파일을 변경하면 다음 중 하나와 유사한 오류가 기록됩니다. |

####

```
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)`. 자세한 내용 은 [참조 가이드](https://docs.spring.io/spring/docs/5.1.7.RELEASE/spring-framework-reference/core.html#beans-definition-profiles-java) 를 확인하십시오. 다음 목록은 세 가지 샘플 프로필을 보여줍니다.

{% hint style="info" %}
참조 <https://supawer0728.github.io/2018/04/07/spring-boot-logging/>
{% endhint %}

####

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

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

| ![\[노트\]](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/images/note.png)          |
| -------------------------------------------------------------------------------------------------------- |
| `source는` 케밥 케이스(?) 에서 구체화되어야한다. (가령 my.property-name). 그러나 `Environment`느슨한 규칙을 사용하여 속성을에 추가 할 수 있습니다 . |
|                                                                                                          |
|                                                                                                          |

{% hint style="info" %}
케밥 케이스 :&#x20;

* [하이픈](https://zetawiki.com/w/index.php?title=%ED%95%98%EC%9D%B4%ED%94%88\&action=edit\&redlink=1)으로 단어를 연결하는 표기법
* HTML 태그의 id, class 속성으로 흔히 쓰임
  {% endhint %}
