Merge branch '2.1.x'

pull/17490/head
Madhura Bhave 5 years ago
commit 6164e3efe8

@ -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> logFile) {
this.loggingSystem = loggingSystem;
this.logFile = logFile.getIfAvailable();
}
}

@ -63,13 +63,6 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
assertThat(entity.getBody()).contains("\"hello\":\"world\"");
}
@Test
void logfileWithRandomName() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
.getForEntity("/admin/logfile", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
private String getPassword() {
return "password";
}

@ -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}

Loading…
Cancel
Save