mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Polish "Add standardized property to distinguish a group of applications"
See gh-39957
This commit is contained in:
parent
8ddb77f628
commit
de001f5af1
@ -28,6 +28,7 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.
|
||||
import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Adapter to convert {@link OtlpProperties} to an {@link OtlpConfig}.
|
||||
@ -43,11 +44,6 @@ class OtlpPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<Ot
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_NAME = "unknown_service";
|
||||
|
||||
/**
|
||||
* Default value for application group if {@code spring.application.group} is not set.
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_GROUP = "unknown_group";
|
||||
|
||||
private final OpenTelemetryProperties openTelemetryProperties;
|
||||
|
||||
private final OtlpMetricsConnectionDetails connectionDetails;
|
||||
@ -93,7 +89,8 @@ class OtlpPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<Ot
|
||||
}
|
||||
|
||||
private String getApplicationGroup() {
|
||||
return this.environment.getProperty("spring.application.group", DEFAULT_APPLICATION_GROUP);
|
||||
String applicationGroup = this.environment.getProperty("spring.application.group");
|
||||
return (StringUtils.hasLength(applicationGroup)) ? applicationGroup : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry.
|
||||
@ -53,11 +54,6 @@ public class OpenTelemetryAutoConfiguration {
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_NAME = "unknown_service";
|
||||
|
||||
/**
|
||||
* Default value for application group if {@code spring.application.group} is not set.
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_GROUP = "unknown_group";
|
||||
|
||||
private static final AttributeKey<String> ATTRIBUTE_KEY_SERVICE_NAME = AttributeKey.stringKey("service.name");
|
||||
|
||||
private static final AttributeKey<String> ATTRIBUTE_KEY_SERVICE_GROUP = AttributeKey.stringKey("service.group");
|
||||
@ -79,11 +75,13 @@ public class OpenTelemetryAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
Resource openTelemetryResource(Environment environment, OpenTelemetryProperties properties) {
|
||||
String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
|
||||
String applicationGroup = environment.getProperty("spring.application.group", DEFAULT_APPLICATION_GROUP);
|
||||
return Resource.getDefault()
|
||||
.merge(Resource.create(Attributes.of(ATTRIBUTE_KEY_SERVICE_NAME, applicationName)))
|
||||
.merge(Resource.create(Attributes.of(ATTRIBUTE_KEY_SERVICE_GROUP, applicationGroup)))
|
||||
.merge(toResource(properties));
|
||||
String applicationGroup = environment.getProperty("spring.application.group");
|
||||
Resource resource = Resource.getDefault()
|
||||
.merge(Resource.create(Attributes.of(ATTRIBUTE_KEY_SERVICE_NAME, applicationName)));
|
||||
if (StringUtils.hasLength(applicationGroup)) {
|
||||
resource = resource.merge(Resource.create(Attributes.of(ATTRIBUTE_KEY_SERVICE_GROUP, applicationGroup)));
|
||||
}
|
||||
return resource.merge(toResource(properties));
|
||||
}
|
||||
|
||||
private static Resource toResource(OpenTelemetryProperties properties) {
|
||||
|
@ -162,7 +162,7 @@ class OtlpPropertiesConfigAdapterTests {
|
||||
|
||||
@Test
|
||||
void shouldUseDefaultApplicationGroupIfApplicationGroupIsNotSet() {
|
||||
assertThat(createAdapter().resourceAttributes()).containsEntry("service.group", "unknown_group");
|
||||
assertThat(createAdapter().resourceAttributes()).doesNotContainKey("service.group");
|
||||
}
|
||||
|
||||
private OtlpPropertiesConfigAdapter createAdapter() {
|
||||
|
@ -90,6 +90,23 @@ class OpenTelemetryAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldApplySpringApplicationGroupToResource() {
|
||||
this.runner.withPropertyValues("spring.application.group=my-group").run((context) -> {
|
||||
Resource resource = context.getBean(Resource.class);
|
||||
assertThat(resource.getAttributes().asMap())
|
||||
.contains(entry(AttributeKey.stringKey("service.group"), "my-group"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotApplySpringApplicationGroupIfNotSet() {
|
||||
this.runner.run((context) -> {
|
||||
Resource resource = context.getBean(Resource.class);
|
||||
assertThat(resource.getAttributes().asMap()).doesNotContainKey(AttributeKey.stringKey("service.group"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFallbackToDefaultApplicationNameIfSpringApplicationNameIsNotSet() {
|
||||
this.runner.run((context) -> {
|
||||
|
@ -204,7 +204,6 @@ The preceding example YAML corresponds to the following `application.properties`
|
||||
[source,properties,subs="verbatim",configprops]
|
||||
----
|
||||
spring.application.name=cruncher
|
||||
spring.application.group=crunchGroup
|
||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://localhost/test
|
||||
server.port=9000
|
||||
|
@ -88,10 +88,9 @@ logging:
|
||||
pattern:
|
||||
correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}] "
|
||||
include-application-name: false
|
||||
include-application-group: false
|
||||
----
|
||||
|
||||
NOTE: In the example above, configprop:logging.include-application-name[] and configprop:logging.include-application-group[] is set to `false` to avoid the application name being duplicated in the log messages (configprop:logging.pattern.correlation[] already contains it).
|
||||
NOTE: In the example above, configprop:logging.include-application-name[] is set to `false` to avoid the application name being duplicated in the log messages (configprop:logging.pattern.correlation[] already contains it).
|
||||
It's also worth mentioning that configprop:logging.pattern.correlation[] contains a trailing space so that it is separated from the logger name that comes right after it by default.
|
||||
|
||||
|
||||
|
@ -44,6 +44,7 @@ NOTE: Logback does not have a `FATAL` level.
|
||||
It is mapped to `ERROR`.
|
||||
|
||||
TIP: If you have a configprop:spring.application.name[] property but don't want it logged you can set configprop:logging.include-application-name[] to `false`.
|
||||
|
||||
TIP: If you have a configprop:spring.application.group[] property but don't want it logged you can set configprop:logging.include-application-group[] to `false`.
|
||||
|
||||
|
||||
|
@ -260,7 +260,7 @@ public class LoggingSystemProperties {
|
||||
if (resolver.getProperty("logging.include-application-group", Boolean.class, Boolean.TRUE)) {
|
||||
String applicationGroup = resolver.getProperty("spring.application.group");
|
||||
if (StringUtils.hasText(applicationGroup)) {
|
||||
setSystemProperty(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName(),
|
||||
setSystemProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP.getEnvironmentVariableName(),
|
||||
"[%s] ".formatted(applicationGroup));
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public enum LoggingSystemProperty {
|
||||
/**
|
||||
* Logging system property for the application group that should be logged.
|
||||
*/
|
||||
APPLICATION_GROUP("LOGGED_APPLICATION_GROUP"),
|
||||
LOGGED_APPLICATION_GROUP("LOGGED_APPLICATION_GROUP"),
|
||||
|
||||
/**
|
||||
* Logging system property for the process ID.
|
||||
|
@ -24,9 +24,9 @@ import org.springframework.boot.logging.LoggingSystemProperty;
|
||||
|
||||
/**
|
||||
* Logback {@link ClassicConverter} to convert the
|
||||
* {@link LoggingSystemProperty#APPLICATION_GROUP APPLICATION_GROUP} into a value suitable
|
||||
* for logging. Similar to Logback's {@link PropertyConverter} but a non-existent property
|
||||
* is logged as an empty string rather than {@code null}.
|
||||
* {@link LoggingSystemProperty#LOGGED_APPLICATION_GROUP APPLICATION_GROUP} into a value
|
||||
* suitable for logging. Similar to Logback's {@link PropertyConverter} but a non-existent
|
||||
* property is logged as an empty string rather than {@code null}.
|
||||
*
|
||||
* @author Jakob Wanger
|
||||
* @since 3.4.0
|
||||
@ -37,9 +37,10 @@ public class ApplicationGroupConverter extends ClassicConverter {
|
||||
public String convert(ILoggingEvent event) {
|
||||
String applicationGroup = event.getLoggerContextVO()
|
||||
.getPropertyMap()
|
||||
.get(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
.get(LoggingSystemProperty.LOGGED_APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
if (applicationGroup == null) {
|
||||
applicationGroup = System.getProperty(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
applicationGroup = System
|
||||
.getProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
if (applicationGroup == null) {
|
||||
applicationGroup = "";
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ class DefaultLogbackConfiguration {
|
||||
}
|
||||
|
||||
private void defaults(LogbackConfigurator config) {
|
||||
config.conversionRule("applicationName", ApplicationNameConverter.class);
|
||||
config.conversionRule("applicationGroup", ApplicationGroupConverter.class);
|
||||
config.conversionRule("applicationName", ApplicationNameConverter.class);
|
||||
config.conversionRule("clr", ColorConverter.class);
|
||||
config.conversionRule("correlationId", CorrelationIdConverter.class);
|
||||
config.conversionRule("wex", WhitespaceThrowableProxyConverter.class);
|
||||
@ -77,7 +77,7 @@ class DefaultLogbackConfiguration {
|
||||
config.getContext()
|
||||
.putProperty("CONSOLE_LOG_PATTERN", resolve(config, "${CONSOLE_LOG_PATTERN:-"
|
||||
+ "%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) "
|
||||
+ "%clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName[%15.15t]){faint} %clr(---){faint} %clr(%applicationGroup[%15.15t]){faint} "
|
||||
+ "%clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName%applicationGroup[%15.15t]){faint} "
|
||||
+ "%clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} "
|
||||
+ "%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"));
|
||||
String defaultCharset = Charset.defaultCharset().name();
|
||||
@ -86,7 +86,7 @@ class DefaultLogbackConfiguration {
|
||||
config.getContext().putProperty("CONSOLE_LOG_THRESHOLD", resolve(config, "${CONSOLE_LOG_THRESHOLD:-TRACE}"));
|
||||
config.getContext()
|
||||
.putProperty("FILE_LOG_PATTERN", resolve(config, "${FILE_LOG_PATTERN:-"
|
||||
+ "%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- %applicationName[%t] --- %applicationGroup[%t] "
|
||||
+ "%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- %applicationName%applicationGroup[%t] "
|
||||
+ "${LOG_CORRELATION_PATTERN:-}"
|
||||
+ "%-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"));
|
||||
config.getContext()
|
||||
|
@ -103,6 +103,13 @@
|
||||
"description": "Log groups to quickly change multiple loggers at the same time. For instance, `logging.group.db=org.hibernate,org.springframework.jdbc`.",
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
|
||||
},
|
||||
{
|
||||
"name": "logging.include-application-group",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to include the application group in the logs.",
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "logging.include-application-name",
|
||||
"type": "java.lang.Boolean",
|
||||
@ -228,6 +235,11 @@
|
||||
"description": "Log level threshold for file output.",
|
||||
"defaultValue": "TRACE"
|
||||
},
|
||||
{
|
||||
"name": "spring.application.group",
|
||||
"type": "java.lang.String",
|
||||
"description": "Application group."
|
||||
},
|
||||
{
|
||||
"name": "spring.application.index",
|
||||
"type": "java.lang.Integer",
|
||||
|
@ -4,8 +4,8 @@
|
||||
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
|
||||
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
|
||||
<Property name="LOG_DATEFORMAT_PATTERN">yyyy-MM-dd'T'HH:mm:ss.SSSXXX</Property>
|
||||
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{${sys:LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${sys:LOG_LEVEL_PATTERN}} %clr{%pid}{magenta} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_NAME:-}[%15.15t]}{faint} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_GROUP:-}[%15.15t]}{faint} %clr{${sys:LOG_CORRELATION_PATTERN:-}}{faint}%clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
<Property name="FILE_LOG_PATTERN">%d{${sys:LOG_DATEFORMAT_PATTERN}} ${sys:LOG_LEVEL_PATTERN} %pid --- ${sys:LOGGED_APPLICATION_NAME:-} --- ${sys:LOGGED_APPLICATION_GROUP:-}[%t] ${sys:LOG_CORRELATION_PATTERN:-}%-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{${sys:LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${sys:LOG_LEVEL_PATTERN}} %clr{%pid}{magenta} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_NAME:-}${sys:LOGGED_APPLICATION_GROUP:-}[%15.15t]}{faint} %clr{${sys:LOG_CORRELATION_PATTERN:-}}{faint}%clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
<Property name="FILE_LOG_PATTERN">%d{${sys:LOG_DATEFORMAT_PATTERN}} ${sys:LOG_LEVEL_PATTERN} %pid --- ${sys:LOGGED_APPLICATION_NAME:-}${sys:LOGGED_APPLICATION_GROUP:-}[%t] ${sys:LOG_CORRELATION_PATTERN:-}%-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
|
@ -4,8 +4,8 @@
|
||||
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
|
||||
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
|
||||
<Property name="LOG_DATEFORMAT_PATTERN">yyyy-MM-dd'T'HH:mm:ss.SSSXXX</Property>
|
||||
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{${sys:LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${sys:LOG_LEVEL_PATTERN}} %clr{%pid}{magenta} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_NAME:-}[%15.15t]} {faint}%clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_GROUP:-}[%15.15t]}{faint} %clr{${sys:LOG_CORRELATION_PATTERN:-}}{faint}%clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
<Property name="FILE_LOG_PATTERN">%d{${sys:LOG_DATEFORMAT_PATTERN}} ${sys:LOG_LEVEL_PATTERN} %pid --- ${sys:LOGGED_APPLICATION_NAME:-} --- ${sys:LOGGED_APPLICATION_GROUP:-}[%t] ${sys:LOG_CORRELATION_PATTERN:-}%-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{${sys:LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${sys:LOG_LEVEL_PATTERN}} %clr{%pid}{magenta} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_NAME:-}${sys:LOGGED_APPLICATION_GROUP:-}[%15.15t]}{faint} %clr{${sys:LOG_CORRELATION_PATTERN:-}}{faint}%clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
<Property name="FILE_LOG_PATTERN">%d{${sys:LOG_DATEFORMAT_PATTERN}} ${sys:LOG_LEVEL_PATTERN} %pid --- ${sys:LOGGED_APPLICATION_NAME:-}${sys:LOGGED_APPLICATION_GROUP:-}[%t] ${sys:LOG_CORRELATION_PATTERN:-}%-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
|
@ -5,17 +5,17 @@ Default logback configuration provided for import
|
||||
-->
|
||||
|
||||
<included>
|
||||
<conversionRule conversionWord="applicationName" converterClass="org.springframework.boot.logging.logback.ApplicationNameConverter" />
|
||||
<conversionRule conversionWord="applicationGroup" converterClass="org.springframework.boot.logging.logback.ApplicationGroupConverter" />
|
||||
<conversionRule conversionWord="applicationName" converterClass="org.springframework.boot.logging.logback.ApplicationNameConverter" />
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||
<conversionRule conversionWord="correlationId" converterClass="org.springframework.boot.logging.logback.CorrelationIdConverter" />
|
||||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
|
||||
|
||||
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName[%15.15t]){faint} %clr(---){faint} %clr(%applicationGroup[%15.15t]){faint} %clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName%applicationGroup[%15.15t]){faint} %clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<property name="CONSOLE_LOG_CHARSET" value="${CONSOLE_LOG_CHARSET:-${file.encoding:-UTF-8}}"/>
|
||||
<property name="CONSOLE_LOG_THRESHOLD" value="${CONSOLE_LOG_THRESHOLD:-TRACE}"/>
|
||||
<property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- %applicationName[%t] --- %applicationGroup[%t] ${LOG_CORRELATION_PATTERN:-}%-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- %applicationName%applicationGroup[%t] ${LOG_CORRELATION_PATTERN:-}%-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<property name="FILE_LOG_CHARSET" value="${FILE_LOG_CHARSET:-${file.encoding:-UTF-8}}"/>
|
||||
<property name="FILE_LOG_THRESHOLD" value="${FILE_LOG_THRESHOLD:-TRACE}"/>
|
||||
|
||||
|
@ -159,20 +159,20 @@ class LoggingSystemPropertiesTests {
|
||||
@Test
|
||||
void loggedApplicationGroupWhenHasApplicationGroup() {
|
||||
new LoggingSystemProperties(new MockEnvironment().withProperty("spring.application.group", "test")).apply(null);
|
||||
assertThat(getSystemProperty(LoggingSystemProperty.APPLICATION_GROUP)).isEqualTo("[test] ");
|
||||
assertThat(getSystemProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP)).isEqualTo("[test] ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggedApplicationGroupWhenHasNoApplicationGroup() {
|
||||
new LoggingSystemProperties(new MockEnvironment()).apply(null);
|
||||
assertThat(getSystemProperty(LoggingSystemProperty.APPLICATION_GROUP)).isNull();
|
||||
assertThat(getSystemProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggedApplicationGroupWhenApplicationGroupLoggingDisabled() {
|
||||
new LoggingSystemProperties(new MockEnvironment().withProperty("spring.application.group", "test")
|
||||
.withProperty("logging.include-application-group", "false")).apply(null);
|
||||
assertThat(getSystemProperty(LoggingSystemProperty.APPLICATION_GROUP)).isNull();
|
||||
assertThat(getSystemProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -65,16 +65,16 @@ class ApplicationGroupConverterTests {
|
||||
|
||||
private void withLoggedApplicationGroup(String group, Runnable action) {
|
||||
if (group == null) {
|
||||
System.clearProperty(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
System.clearProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
}
|
||||
else {
|
||||
System.setProperty(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName(), group);
|
||||
System.setProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP.getEnvironmentVariableName(), group);
|
||||
}
|
||||
try {
|
||||
action.run();
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(LoggingSystemProperty.APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
System.clearProperty(LoggingSystemProperty.LOGGED_APPLICATION_GROUP.getEnvironmentVariableName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
spring.application.name=sample
|
||||
spring.application.group=sample-group
|
||||
#logging.include-application-name=false
|
||||
#logging.include-application-group=false
|
||||
spring.security.user.name=user
|
||||
spring.security.user.password=password
|
||||
management.endpoint.shutdown.enabled=true
|
||||
|
@ -2,7 +2,7 @@
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
<Properties>
|
||||
<Property name="PID">????</Property>
|
||||
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_NAME:-}[%15.15t]}{faint} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_GROUP:-}[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx</Property>
|
||||
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{${sys:LOGGED_APPLICATION_NAME:-}${sys:LOGGED_APPLICATION_GROUP:-}[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
|
@ -1,5 +1,7 @@
|
||||
spring.application.name=sample
|
||||
spring.application.group=sample-group
|
||||
#logging.include-application-name=false
|
||||
#logging.include-application-group=false
|
||||
service.name=Phil
|
||||
|
||||
spring.security.user.name=user
|
||||
|
Loading…
Reference in New Issue
Block a user