spring boot 환경에서 log를 남기는 설정을 logback을 사용한다면 Logstash 를 이용해서 ElasticSearch에 로그를 보내기도 합니다.
net.logstash.logback.encoder.LogstashEncoder 사용
pom.xml 에 아래의 의존성을 추가합니다. 버전은 각 프로젝트의 spring boot 버전에 호환되도록 선택해주세요.
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>x.x</version>
</dependency>
logback-spring.xml 설정
logback-spring.xml 에서 customFields 설정을 해줘서 ElasticSearch에 특정 log가 남도록 합니다.
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeCallerInfo>true</includeCallerInfo>
<customFields>{"application": "testsvc", "build":"1.0.1", "env": "real"}</customFields>
</encoder>