Skip to content

Configuration option for choosing at for which status codes to log stacktrace #512

@EsbenNedergaard

Description

@EsbenNedergaard

Is your feature request related to RFC7807? Please describe.
This is not related to RFC7807

Description of problem
In some of our services we would very much like to always log the stack trace whenever something goes wrong such as a 403-Forbidden.

However the current setup for the ProblemLogger only logs stack traces if status code is 500 or above. Problem Logger

Describe the solution you'd like

Something simlar to this would be nice to be able to control at which cutoff point you start logging info instead of error:

/**
 * Logs problems with ERROR (for HTTP with status above threshold default = 500) or INFO (other exceptions) log level.
 * In case of ERROR stack trace is printed as well.
 */
final class ProblemLogger implements ProblemPostProcessor {

    private final Logger logger;

    ProblemLogger(Logger logger) {
        this.logger = logger;
    }

    @ConfigProperty(name = "quarkus.resteasy.problem.status-code-threshold", defaultValue = "500")
    int statusCodeThreshold;

    @Override
    public HttpProblem apply(HttpProblem problem, ProblemContext context) {
        if (!logger.isErrorEnabled()) {
            return problem;
        }

        if (problem.getStatusCode() >= statusCodeThreshold) {
            if (logger.isErrorEnabled()) {
                logger.error(serialize(problem), context.cause);
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info(serialize(problem));
            }
        }
        return problem;
    }

   // ... more code - that was cut out for simplicity
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions