Categorygithub.com/beatlabs/ctxlog
modulepackage
0.2.0
Repository: https://github.com/beatlabs/ctxlog.git
Documentation: pkg.go.dev

# README

Context Logger CI

ctxlog is a library which helps to add a contextual data to your log messages at any time, and have it logged with each message.

Short-term plans

TBD but be aware it might happen

  • Remove dependency on Patron and replace it with some generic logger
  • Add examples in examples/ folder

Install it

To add this library as a dependency of your project, run

$ go get github.com/beatlabs/ctxlog

Usage examples

Initiate a logger in a request context

req := &http.Request{}

ctx := ctxlog.AddLoggerForRequest(req)

Add some custom data to it

ctxlog.FromContext(ctx).Int("answer", 42)
ctxlog.FromContext(ctx).Str("so", "long")
ctxlog.FromContext(ctx).SubCtx(map[string]interface{}{
    "thanks_for":  "all the fish",
    "planet":      "Earth",
    "happened_on": "Thursday",
})

And log it

ctxlog.FromContext(ctx).Warnf("this %s has — or rather had — a %s, which was this: %s", "planet", "problem",
	"most of the people living on it were unhappy for pretty much all of the time")

# Packages

No description provided by the author

# Functions

AddLoggerForRequest adds a ctx logger to the context of an HTTP request.
FromContext associates logger with a context and returns both the context and the logger.

# Constants

List of header values that should be forwarded during login.
Constants for context data.
CtxKey json key on which the context data is logged.
List of header values that should be forwarded during login.
Constants for context data.
Constants for context data.
List of header values that should be forwarded during login.
Constants for context data.
List of header values that should be forwarded during login.

# Structs

CtxLogger is a logger implementation that delegates logging fully to Patron and always adds some logging context to a message.