imax9000 / ctxlog

Simple wrapper for using logrus with context.Context

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrappers for using logrus with context.Context

GoDoc

Example usage:

ctx = ctxlog.WithField(ctx, "user", user)
// ...
ctxlog.With(ctx).Printf("User did something")  // resulting entry will have field "user"

You can also use it to trace request handling across function boundaries:

func handleHTTP(w http.ResponseWriter, r *http.Request) {
    ctx := ctxlog.WithField(context.Background(), "request_id", genRequestID())
    doStuff(ctx)  // if doStuff uses ctxlog too, all entries will have "request_id"
    // ...

About

Simple wrapper for using logrus with context.Context

License:MIT License


Languages

Language:Go 100.0%