Go to file
Marvin Steadfast c072642dbb
All checks were successful
continuous-integration/drone/push Build is passing
sets lint timeout to 10m
2021-02-16 14:26:28 +01:00
vendor first commit 2020-10-13 15:26:40 +02:00
.drone.yml first commit 2020-10-13 15:26:40 +02:00
.gitignore first commit 2020-10-13 15:26:40 +02:00
.goreleaser.yml first commit 2020-10-13 15:26:40 +02:00
go.mod vanity go module url 2021-01-18 11:02:17 +01:00
go.sum first commit 2020-10-13 15:26:40 +02:00
LICENSE adds MIT license 2021-01-18 11:20:31 +01:00
logginghandler_test.go more docs 2021-01-18 11:46:22 +01:00
logginghandler.go more docs 2021-01-18 11:46:22 +01:00
Makefile sets lint timeout to 10m 2021-02-16 14:26:28 +01:00
README.md fixes typo in readme 2021-02-16 13:37:43 +01: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")