logctx

MIT License

Stars
0

logctx

Utility library for logging.

Usage

Adding a logger into a context.Context:

// ...
ctx = logctx.WithLogger(ctx, logger.With(zap.String("request_id", ulid.New().String())))
// Now the logger inside of `ctx` has `request_id` as field.
// ...

Extracting a logger from a context.Context:

// ...
logger := logctx.From(ctx)
// Now you can use logger as you wish.
// ...