class PutLogLevel implements Handler {

  @OpenApi(
      path = ROUTE,
      method = HttpMethod.PUT,
      summary = "Changes the log level without restarting.",
      tags = {TAG_ADMIN},
      requestBody =
          @OpenApiRequestBody(
              content = {@OpenApiContent(from = LogLevel.class)},
              description =
                  "```\n{\n  \"level\": (String; acceptable values: ALL, TRACE, DEBUG, INFO, ERROR, FATAL, OFF ),\n"
                      + "  \"log_filter\": [(String; Optional)]\n}\n```"),
      description =
          "Changes the log level without restarting. You can change the log level for all logs, or the log level for specific packages or classes.",
      responses = {
        @OpenApiResponse(
            status = RES_NO_CONTENT,
            description = "The LogLevel was accepted and applied"),
        @OpenApiResponse(status = RES_BAD_REQUEST, description = INVALID_BODY_SUPPLIED),
        @OpenApiResponse(status = RES_INTERNAL_ERROR)
      })
  @Override
  public void handle(final Context ctx) throws Exception {

    try {
      final LogLevel params = jsonProvider.jsonToObject(ctx.body(), LogLevel.class);

      final String[] logFilters = params.getLogFilter().orElseGet(() -> new String[] {""});

      for (final String logFilter : logFilters) {
        LoggingConfigurator.setAllLevels(logFilter, params.getLevel());
      }

      ctx.status(SC_NO_CONTENT);
    } catch (final IllegalArgumentException | JsonMappingException e) {
      ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage())));
      ctx.status(SC_BAD_REQUEST);
    }
  }

  public  PutLogLevel(final JsonProvider jsonProvider);

}