Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +32,7 @@
*
* @author Ben Hale
* @author Kazuki Shimizu
* @author Eddú Meléndez
* @since 1.5.0
*/
@ConfigurationProperties(prefix = "endpoints.loggers")
Expand Down Expand Up @@ -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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
*
* @author Ben Hale
* @author Phillip Webb
* @author Eddú Meléndez
*/
@RunWith(SpringRunner.class)
@SpringBootTest
Expand Down Expand Up @@ -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,
Expand Down