diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpoint.java index 0ede3e749f..77b1d400db 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpoint.java @@ -22,10 +22,12 @@ import org.springframework.boot.actuate.endpoint.LoggersEndpoint; import org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.logging.LogLevel; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; /** * Adapter to expose {@link LoggersEndpoint} as an {@link MvcEndpoint}. @@ -74,7 +76,7 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter { return ResponseEntity.ok().build(); } catch (IllegalArgumentException ex) { - return ResponseEntity.badRequest().build(); + throw new InvalidLogLevelException("No such log level " + configuration.get("configuredLevel")); } } @@ -83,4 +85,17 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter { return (level == null ? null : LogLevel.valueOf(level.toUpperCase())); } + /** + * Exception thrown when the specified log level cannot be found. + */ + @SuppressWarnings("serial") + @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "No such log level") + public static class InvalidLogLevelException extends RuntimeException { + + public InvalidLogLevelException(String string) { + super(string); + } + + } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java index 499062e206..a6234dddc7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java @@ -49,6 +49,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -174,7 +175,8 @@ public class LoggersMvcEndpointTests { public void setLoggerWithWrongLogLevel() throws Exception { this.mvc.perform(post("/loggers/ROOT").contentType(MediaType.APPLICATION_JSON) .content("{\"configuredLevel\":\"other\"}")) - .andExpect(status().is4xxClientError()); + .andExpect(status().is4xxClientError()) + .andExpect(status().reason(is("No such log level"))); verifyZeroInteractions(this.loggingSystem); }