Skip to content

Use different log level based on the HTTP status #2232

@Airidas36

Description

@Airidas36

By default, org.zalando.logbook.Logbook writes request and response entries at TRACE level only. It would be nice that based on the HTTP response code, the corresponding HTTP response entry could be logged on a WARN/ERROR level.

Detailed Description

Use different log levels, to clearly separate successful HTTP responses from error ones. At the moment this requires creating multiple custom HttpLogWriter for every log level and a custom Sink to trigger the corresponding writer based on the HTTP response code. Configuring this for multiple microservices quickly becomes a maintenance job, because you either have to copy paste the same configuration everywhere, or try and maintain some custom Spring Boot Starter that exposes the Sink @Bean

Context

Logging 4xx responses as WARN and 5xx as ERROR (or consolidating both of them under ERROR) improves observability and alerting while keeping normal traffic at TRACE.

Possible Implementation

Maybe a Sink which resolves the HTTP response code and delegates to corresponding HttpLogWriter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions