diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java index 1672c48d9ab..adb5985150e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java @@ -16,14 +16,19 @@ package org.springframework.boot.context.logging; +import java.io.File; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.event.ApplicationStartingEvent; +import org.springframework.boot.logging.LogFile; import org.springframework.boot.logging.LoggingSystem; import org.springframework.boot.testsupport.system.CapturedOutput; import org.springframework.boot.testsupport.system.OutputCaptureExtension; @@ -50,6 +55,17 @@ class LoggingApplicationListenerIntegrationTests { } } + @Test + void logFileRegisteredInTheContextWhenApplicable(@TempDir File tempDir) throws Exception { + String logFile = new File(tempDir, "test.log").getAbsolutePath(); + try (ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class) + .web(WebApplicationType.NONE).properties("logging.file=" + logFile).run()) { + SampleService service = context.getBean(SampleService.class); + assertThat(service.logFile).isNotNull(); + assertThat(service.logFile.toString()).isEqualTo(logFile); + } + } + @Test void loggingPerformedDuringChildApplicationStartIsNotLost(CapturedOutput capturedOutput) { new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).child(Config.class) @@ -71,8 +87,11 @@ class LoggingApplicationListenerIntegrationTests { private final LoggingSystem loggingSystem; - SampleService(LoggingSystem loggingSystem) { + private final LogFile logFile; + + SampleService(LoggingSystem loggingSystem, ObjectProvider logFile) { this.loggingSystem = loggingSystem; + this.logFile = logFile.getIfAvailable(); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 0f6d12e55b7..41922918f70 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -63,13 +63,6 @@ class EndpointsPropertiesSampleActuatorApplicationTests { assertThat(entity.getBody()).contains("\"hello\":\"world\""); } - @Test - void logfileWithRandomName() { - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/admin/logfile", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - private String getPassword() { return "password"; } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/resources/application-endpoints.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/resources/application-endpoints.properties index fab27a09e53..5f8c1d2bedd 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/resources/application-endpoints.properties +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/resources/application-endpoints.properties @@ -1,5 +1,3 @@ -server.error.path: /oops -management.endpoint.health.show-details: always -management.endpoints.web.base-path: /admin -logging.file=./target/${spring.application.instance_id}.log -spring.application.instance_id=${random.value} +server.error.path:/oops +management.endpoint.health.show-details:always +management.endpoints.web.base-path:/admin