Search in sources :

Example 1 with LogLevel

use of tech.pegasys.teku.api.schema.LogLevel in project teku by ConsenSys.

the class PutLogLevel method handle.

@OpenApi(path = ROUTE, method = HttpMethod.PUT, summary = "Changes the log level without restarting.", tags = { TAG_TEKU }, 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 = parseRequestBody(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 e) {
        ctx.json(jsonProvider.objectToJSON(new BadRequest(e.getMessage())));
        ctx.status(SC_BAD_REQUEST);
    }
}
Also used : BadRequest(tech.pegasys.teku.beaconrestapi.schema.BadRequest) LogLevel(tech.pegasys.teku.api.schema.LogLevel) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Aggregations

OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)1 LogLevel (tech.pegasys.teku.api.schema.LogLevel)1 BadRequest (tech.pegasys.teku.beaconrestapi.schema.BadRequest)1