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

# Packages

No description provided by the author

# 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)