Merge branch '2.1.x'

This commit is contained in:
Madhura Bhave 2019-07-10 18:26:25 -07:00
commit 6164e3efe8
3 changed files with 23 additions and 13 deletions

View File

@ -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();
}
}

View File

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

View File

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