Skip to content

Latest commit

 

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test Go Reference

ctxslog

handler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ReplaceAttr: replace})
slog.SetDefault(slog.New(ctxslog.New(handler)))

ctx := context.Background()
// associate the key my_context and the value foo-bar with the context.
ctx = ctxslog.With(ctx, "my_context", "foo-bar")

slog.InfoContext(ctx, "hello", "count", 42)
slog.InfoContext(ctx, "world")
// Output:
// time=2023-08-03T18:10:20.424+09:00 level=INFO msg=hello count=42 my_context=foo-bar
// time=2023-08-03T18:10:20.424+09:00 level=INFO msg=world my_context=foo-bar

About

log/slog handler that gets attributes from the context

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages