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 fc8e15aabf1e..d582330442ef 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,7 +22,6 @@ 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.HttpEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -33,6 +32,7 @@ * * @author Ben Hale * @author Kazuki Shimizu + * @author Eddú Meléndez * @since 1.5.0 */ @ConfigurationProperties(prefix = "endpoints.loggers") @@ -69,9 +69,14 @@ public Object set(@PathVariable String name, return getDisabledResponse(); } String level = configuration.get("configuredLevel"); - LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase()); - this.delegate.setLogLevel(name, logLevel); - return HttpEntity.EMPTY; + try { + LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase()); + this.delegate.setLogLevel(name, logLevel); + return ResponseEntity.ok().build(); + } + catch (IllegalArgumentException ex) { + return ResponseEntity.badRequest().build(); + } } } 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 bc67e6421c0a..ac04663ec6c6 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 @@ -64,6 +64,7 @@ * * @author Ben Hale * @author Phillip Webb + * @author Eddú Meléndez */ @RunWith(SpringRunner.class) @SpringBootTest @@ -169,6 +170,14 @@ public void setLoggerWhenDisabledShouldReturnNotFound() throws Exception { verifyZeroInteractions(this.loggingSystem); } + @Test + public void setLoggerWithWrongLogLevel() throws Exception { + this.mvc.perform(post("/loggers/ROOT").contentType(MediaType.APPLICATION_JSON) + .content("{\"configuredLevel\":\"other\"}")) + .andExpect(status().is4xxClientError()); + verifyZeroInteractions(this.loggingSystem); + } + @Configuration @Import({ JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,