Categorygithub.com/koenbollen/logging
modulepackage
0.0.0-20240902195117-68ecf3698e91
Repository: https://github.com/koenbollen/logging.git
Documentation: pkg.go.dev

# README

logging Go Reference

Using Go's log/slog in all my project I found myself repeating a small amount of bootstrap and http middleware. Then when all my projects weren't Stackdriver compabitble I decided to create a small package for this:

  • Highly opinionated
  • Stackdriver compatible
  • Heavy use of the context.Context
  • Sets default logger using slog.SetDefault()
  • Uses jussi-kalliokoski/slogdriver for Stackdriver logging
  • ..and lmittmann/tint for colorized console output

Usage

ctx := context.Background()

logger := logging.New(ctx, "myservice", "example")
logger.Info("hello, world!!")

ctx = logging.WithLogger(ctx, logger)
err := someOperation(ctx)
logger.Error("failed", "err", err)

(see this example for a more extensive example of using logging in a http service)

# Packages

No description provided by the author

# Functions

GetLogger will retrieve a logger from the given context.
GetRequestID will return the generated request id that the logging.Middleware has generated and attached to the http.Request's context.
No description provided by the author
No description provided by the author
Middleware wraps the given next http.Handler.
New creates a new *slog.Logger configured based on the environment variables ENV, DEBUG and VERSION.
WithLogger will attach the given logger to a parent context.