Commit fccab427 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #8813 from eddumelendez:gh-8798

* pr/8813:
  Polish "Fix http status code with unknown log level"
  Fix http status code with unknown log level
parents 934d3368 82ac8b5c
......@@ -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")
......@@ -68,10 +68,17 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
// disabled
return getDisabledResponse();
}
String level = configuration.get("configuredLevel");
LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase());
LogLevel logLevel;
try {
String level = configuration.get("configuredLevel");
logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase());
}
catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().build();
}
this.delegate.setLogLevel(name, logLevel);
return HttpEntity.EMPTY;
return ResponseEntity.ok().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