Skip to content
/ logem Public

A simple slog handler wrapper which adds level handling and tracing ability.

License

Notifications You must be signed in to change notification settings

mgjules/logem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logem

Go Doc License

Logem, short for "Let's Log em!", is an opinionated handler wrapper for slog.

It combines a LevelHandler and a TraceHandler in a single, simple to use handler.

Disclaimer

This package is not suited for production use right now. It is heavily being worked on.

However feel free to inspire yourself from it or fork it.

Installation

go get -u github.com/mgjules/logem

Usage

package main

import (
  "context"
  "os"

  "github.com/mgjules/logem"
  "golang.org/x/exp/slog"
)

func main() {
  // Init OTEL trace provider.
  // initTraceProvider()

  // Create logger using logem.Handler.
  logger := slog.New(
    logem.NewHandler(
      slog.NewTextHandler(os.Stdout),
      logem.WithMinLevel(slog.LevelInfo),
      logem.WithStackTrace(true),
      logem.WithTraceID(true),
      logem.WithSpanID(true),
    ),
  )
  slog.SetDefault(logger)

  // Use logger to log messages, etc.
  // Please ensure that the context being passed has proper trace information.
  ctx := context.TODO()
  logger.WithContext(ctx).Info("hello", "count", 3)
}

Stability

This project follows SemVer strictly and is not yet v1.

Breaking changes might be introduced until v1 is released.

This project follows the Go Release Policy. Each major version of Go is supported until there are two newer major releases.

About

A simple slog handler wrapper which adds level handling and tracing ability.

Topics

Resources

License

Stars

Watchers

Forks

Languages