Skip to content

Commit 88716a4

Browse files
authored
Merge pull request #10 from spt-development/feature/MDC
Updated auto configuration so that the correlation ID is not included…
2 parents fdaea99 + c07b6fc commit 88716a4

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<!-- Dependency versions -->
4040
<spring-boot.version>2.7.5</spring-boot.version>
4141
<spt-cid.version>2.0.11</spt-cid.version>
42-
<spt-logging-spring.version>2.0.7</spt-logging-spring.version>
42+
<spt-logging-spring.version>2.0.8</spt-logging-spring.version>
4343

4444
<!-- Plugin versions -->
4545
<checkstyle-maven-plugin.version>3.1.2</checkstyle-maven-plugin.version>

spt-development-logging-spring-boot-autoconfigure/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
<dependencies>
1818
<!-- Spring dependencies - version defined in spring-boot bom, import in parent dependencyManagement section -->
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-beans</artifactId>
22+
</dependency>
1923
<dependency>
2024
<groupId>org.springframework</groupId>
2125
<artifactId>spring-context</artifactId>

spt-development-logging-spring-boot-autoconfigure/src/main/java/com/spt/development/logging/spring/boot/autoconfigure/LoggingSpringAutoConfiguration.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.spt.development.logging.spring.RepositoryLogger;
55
import com.spt.development.logging.spring.RestControllerLogger;
66
import com.spt.development.logging.spring.ServiceLogger;
7+
import org.springframework.beans.factory.annotation.Value;
78
import org.springframework.boot.autoconfigure.AutoConfiguration;
89
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
910
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -17,50 +18,66 @@
1718
*/
1819
@AutoConfiguration
1920
public class LoggingSpringAutoConfiguration {
21+
private final boolean mdcDisabled;
2022

2123
/**
22-
* Creates a vanilla {@link RestControllerLogger} (aspect) bean.
24+
* Creates a new instance of the configuration bean with the spt.cid.mdc.disabled property.
25+
*
26+
* @param mdcDisabled a flag to determine whether the correlation ID can be expected to be in the MDC or not. If
27+
* <code>false</code> then the loggers will explicitly include the current correlation ID in
28+
* the log statements added by the aspects.
29+
*/
30+
public LoggingSpringAutoConfiguration(@Value("${spt.cid.mdc.disabled:false}") final boolean mdcDisabled) {
31+
this.mdcDisabled = mdcDisabled;
32+
}
33+
34+
/**
35+
* Creates a {@link RestControllerLogger} (aspect) bean. If the <code>spt.cid.mdc.disabled</code> property is set to
36+
* <code>true</code>, the correlation ID will be included in the generated log statements.
2337
*
2438
* @return a new {@link RestControllerLogger} bean.
2539
*/
2640
@Bean
2741
@ConditionalOnMissingBean
2842
@ConditionalOnClass({ RestController.class })
2943
public RestControllerLogger restControllerLogger() {
30-
return new RestControllerLogger();
44+
return new RestControllerLogger(mdcDisabled);
3145
}
3246

3347
/**
34-
* Creates a vanilla {@link JmsListenerLogger} (aspect) bean.
48+
* Creates a {@link JmsListenerLogger} (aspect) bean. If the <code>spt.cid.mdc.disabled</code> property is set to
49+
* <code>true</code>, the correlation ID will be included in the generated log statements.
3550
*
3651
* @return a new {@link JmsListenerLogger} bean.
3752
*/
3853
@Bean
3954
@ConditionalOnMissingBean
4055
@ConditionalOnClass({ JmsListener.class })
4156
public JmsListenerLogger jmsListenerLogger() {
42-
return new JmsListenerLogger();
57+
return new JmsListenerLogger(mdcDisabled);
4358
}
4459

4560
/**
46-
* Creates a vanilla {@link ServiceLogger} (aspect) bean.
61+
* Creates a {@link ServiceLogger} (aspect) bean. If the <code>spt.cid.mdc.disabled</code> property is set to
62+
* <true>true</true>, the correlation ID will be included in the generated log statements.
4763
*
4864
* @return a new {@link ServiceLogger} bean.
4965
*/
5066
@Bean
5167
@ConditionalOnMissingBean
5268
public ServiceLogger serviceLogger() {
53-
return new ServiceLogger();
69+
return new ServiceLogger(mdcDisabled);
5470
}
5571

5672
/**
57-
* Creates a vanilla {@link RepositoryLogger} (aspect) bean.
73+
* Creates a vanilla {@link RepositoryLogger} (aspect) bean. If the <code>spt.cid.mdc.disabled</code> property is
74+
* set to <code>true</code>, the correlation ID will be included in the generated log statements.
5875
*
5976
* @return a new {@link RepositoryLogger} bean.
6077
*/
6178
@Bean
6279
@ConditionalOnMissingBean
6380
public RepositoryLogger repositoryLogger() {
64-
return new RepositoryLogger();
81+
return new RepositoryLogger(mdcDisabled);
6582
}
6683
}

0 commit comments

Comments
 (0)