Commit cf081621 authored by Eddú Meléndez's avatar Eddú Meléndez Committed by Stephane Nicoll

Fix http status code with unknown log level

This commit changes the http status code to 400 when an unknown log level
is specified.

Closes gh-8798
See gh-8813
parent 934d3368
......@@ -22,7 +22,6 @@ 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.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -33,6 +32,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*
* @author Ben Hale
* @author Kazuki Shimizu
* @author Eddú Meléndez
* @since 1.5.0
*/
@ConfigurationProperties(prefix = "endpoints.loggers")
......@@ -69,9 +69,14 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
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();
}
}
}
......@@ -64,6 +64,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*
* @author Ben Hale
* @author Phillip Webb
* @author Eddú Meléndez
*/
@RunWith(SpringRunner.class)
@SpringBootTest
......@@ -169,6 +170,14 @@ public class LoggersMvcEndpointTests {
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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment