Skip to content

Supporting functionality related to the log/slog package.

License

Notifications You must be signed in to change notification settings

azazeal/slogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Report Go Reference

slogger

Package slogger implements supporting functionality related to the log/slog package.

For more details, you may review the package documentation here.

Usage

package main

import (
	"context"

	"github.com/azazeal/slogger"
)

func main() {
	// grab a reference to a slog.Logger configured by the $LOG_LEVEL & $LOG_FORMAT environment
	// variables.
	logger := slogger.FromEnv()

	// store that reference to a top-level Context that propagates throughout the program
	ctx := slogger.NewContext(context.Background(), logger)

	// pass the Context, and therefore the slog.Logger, around; log as needed
	doSomething(ctx)
	doSomethingElse(ctx)
}

func doSomething(ctx context.Context) {
	logger := slogger.FromContext(ctx)

	logger.Warn("did something")
}

func doSomethingElse(ctx context.Context) {
	logger := slogger.FromContext(ctx)

	logger.Info("did something else")
}

About

Supporting functionality related to the log/slog package.

Topics

Resources

License

Stars

Watchers

Forks

Languages