diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatProperties.java index 0e671c216f..4cb0491afe 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatProperties.java @@ -32,7 +32,7 @@ import org.springframework.util.StringUtils; */ public record GraylogExtendedLogFormatProperties(String host, Service service) { - static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, Service.NONE); + static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, null); public GraylogExtendedLogFormatProperties(String host, Service service) { this.host = host; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatPropertiesTests.java index 71d2f02ec2..f030323647 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatPropertiesTests.java @@ -46,7 +46,7 @@ class GraylogExtendedLogFormatPropertiesTests { MockEnvironment environment = new MockEnvironment(); environment.setProperty("logging.structured.gelf.host", "spring"); GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment); - assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", Service.NONE)); + assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service(null))); } @Test @@ -58,6 +58,15 @@ class GraylogExtendedLogFormatPropertiesTests { assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3"))); } + @Test + void getBindsFromEnvironmentWhenVersionIsPresentAndHostIsMissingUsesApplicationName() { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("spring.application.name", "spring"); + environment.setProperty("logging.structured.gelf.service.version", "1.2.3"); + GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment); + assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3"))); + } + @Test void getWhenNoServiceNameUsesApplicationName() { MockEnvironment environment = new MockEnvironment();