schnutibox/vendor/go.xsfx.dev/logginghandler
Marvin Steadfast 35fe4a04df
Some checks failed
continuous-integration/drone/push Build is failing
implemented a rough sse logger
2021-05-03 14:51:53 +02:00
..
.drone.yml implemented a rough sse logger 2021-05-03 14:51:53 +02:00
.gitignore implemented a rough sse logger 2021-05-03 14:51:53 +02:00
.goreleaser.yml implemented a rough sse logger 2021-05-03 14:51:53 +02:00
go.mod implemented a rough sse logger 2021-05-03 14:51:53 +02:00
go.sum implemented a rough sse logger 2021-05-03 14:51:53 +02:00
LICENSE implemented a rough sse logger 2021-05-03 14:51:53 +02:00
logginghandler.go implemented a rough sse logger 2021-05-03 14:51:53 +02:00
Makefile implemented a rough sse logger 2021-05-03 14:51:53 +02:00
README.md implemented a rough sse logger 2021-05-03 14:51:53 +02:00

logginghandler

Build Status Go Reference Go Report Card

Just a simple zerolog based request logging http middleware. It also sets a X-Request-ID in the request and response headers.

Install

    go get -v go.xsfx.dev/logginghandler

Usage

    handler := logginghandler.Handler(http.HandlerFunc(myHandler))
    http.Handle("/", handler)
    log.Fatal().Msg(http.ListenAndServe(":5000", nil).Error())

In other handlers you can access the UUID:

    func anotherHandler(w http.ResponseWriter, r *http.Request) {
            fmt.Fprintf(w, "your uuid is: %s", logginghandler.GetUUID(r))
    }

The already prepared logger is also available:

    l := logginghandler.Logger(r)
    l.Info().Msg("foo bar")