Skip to content

Commit

Permalink
Merge branch '3.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jan 19, 2025
2 parents af29ff5 + 9036249 commit 44f5fb2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,12 @@
*/
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;
this.service = (service != null) ? service : Service.NONE;
}

GraylogExtendedLogFormatProperties withDefaults(Environment environment) {
String name = withFallbackProperty(environment, this.host, "spring.application.name");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,32 @@ void getBindsFromEnvironment() {
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
}

@Test
void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissing() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.gelf.host", "spring");
GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service(null)));
}

@Test
void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissingUsesApplicationVersion() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.gelf.host", "spring");
environment.setProperty("spring.application.version", "1.2.3");
GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
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();
Expand Down

0 comments on commit 44f5fb2

Please sign in to comment.