labstack / echo

High performance, minimalist Go web framework
https://echo.labstack.com
MIT License
29.01k stars 2.21k forks source link

DefaultHTTPErrorHandler does not log #2585

Closed linglingqi007 closed 5 months ago

linglingqi007 commented 5 months ago

Issue Description

DefaultHTTPErrorHandler does not record the err returned by handler

Checklist

Expected behaviour

image

Actual behaviour

No errors logged

image

Steps to reproduce

Returns an error in the handler

Working code to debug

package main

func main() {
    e := echo.New()
    e.GET("/", func(ctx echo.Context) error {
        return fmt.Errorf("hello")
    })
    e.Start(":7123")
}

Version/commit

v4.11.4

aldas commented 5 months ago

DefaultHTTPErrorHandler is not meant to log errors. It is meant to send error responses. It logs errors only for cases when writing the response failed. To log errors use:

linglingqi007 commented 5 months ago

DefaultHTTPErrorHandler is not meant to log errors. It is meant to send error responses. It logs errors only for cases when writing the response failed. To log errors use:

The feeling of documentation can be misleading.

image image

The other part of the tutorial documents both the ERR returned by the handler and the ERR that ultimately sends the response.

But it's actually as you said,It logs errors only for cases when writing the response failed.

aldas commented 5 months ago

I will take a look at Echo docs and see if I can improve things.

Notes for other readers in future: