diff --git a/src/main/java/pl/piomin/logging/config/SpringLoggingAutoConfiguration.java b/src/main/java/pl/piomin/logging/config/SpringLoggingAutoConfiguration.java index e07e00a..0b21cf8 100644 --- a/src/main/java/pl/piomin/logging/config/SpringLoggingAutoConfiguration.java +++ b/src/main/java/pl/piomin/logging/config/SpringLoggingAutoConfiguration.java @@ -7,6 +7,7 @@ import net.logstash.logback.appender.LogstashTcpSocketAppender; import net.logstash.logback.encoder.LogstashEncoder; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -19,6 +20,7 @@ import pl.piomin.logging.filter.SpringLoggingFilter; import pl.piomin.logging.util.UniqueIDGenerator; +import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -36,6 +38,8 @@ public class SpringLoggingAutoConfiguration { Optional trustStoreLocation; @Value("${spring.logstash.ssl.trustStorePassword:#{null}}") Optional trustStorePassword; + @Autowired(required = false) + Optional template; @Bean public UniqueIDGenerator generator() { @@ -84,4 +88,13 @@ public LogstashTcpSocketAppender logstashAppender() { return logstashTcpSocketAppender; } + @PostConstruct + public void init() { + template.ifPresent(restTemplate -> { + List interceptorList = new ArrayList(); + interceptorList.add(new RestTemplateSetHeaderInterceptor()); + restTemplate.setInterceptors(interceptorList); + }); + } + }