@ -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 } .
@ -68,19 +70,32 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
// disabled
return getDisabledResponse ( ) ;
}
LogLevel logLevel = getLogLevel ( configuration ) ;
this . delegate . setLogLevel ( name , logLevel ) ;
return ResponseEntity . ok ( ) . build ( ) ;
}
private LogLevel getLogLevel ( Map < String , String > configuration ) {
String level = configuration . get ( "configuredLevel" ) ;
try {
LogLevel logLevel = getLogLevel ( configuration ) ;
this . delegate . setLogLevel ( name , logLevel ) ;
return ResponseEntity . ok ( ) . build ( ) ;
return ( level = = null ? null : LogLevel . valueOf ( level . toUpperCase ( ) ) ) ;
}
catch ( IllegalArgumentException ex ) {
return ResponseEntity . badRequest ( ) . build ( ) ;
throw new InvalidLogLevelException ( level ) ;
}
}
private LogLevel getLogLevel ( Map < String , String > configuration ) {
String level = configuration . get ( "configuredLevel" ) ;
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 level ) {
super ( "Log level '" + level + "' is invalid" ) ;
}
}
}