Go to file
2022-01-17 11:26:34 +01:00
third_party/tools build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
vendor build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
.drone.yml build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
.gitignore envrc gitignore 2021-02-16 14:27:26 +01:00
.goreleaser.yml first commit 2020-10-13 15:26:40 +02:00
go.mod build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
go.sum build: uses go modules for tool handling 2022-01-14 13:51:56 +01:00
LICENSE adds MIT license 2021-01-18 11:20:31 +01:00
logginghandler_test.go feat: base the lib on rs/zerolog/hlog 2022-01-14 13:48:41 +01:00
logginghandler.go feat: base the lib on rs/zerolog/hlog 2022-01-14 13:48:41 +01:00
Makefile build: disabling test cache and ignoring varnamelen in lint 2022-01-17 11:26:34 +01:00
README.md docs(README): updated example 2022-01-14 13:55:05 +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

    logger := log.With().Logger()
    handler := logginghandler.Handler(logger)(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")