Skip to content
/ pkgslog Public
forked from reugn/pkgslog

A package level structured log/slog handler for Go

License

Notifications You must be signed in to change notification settings

jippi/pkgslog

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pkgslog

Build PkgGoDev Go Report Card codecov

A package level structured log handler for log/slog.
pkgslog adds the ability to set minimum log level requirement per package.

Example

textHandler := slog.NewTextHandler(os.Stdout, nil)
packageMap := map[string]slog.Level{
    "github.com/reugn/pkgslog/internal":  slog.LevelWarn,
    "github.com/reugn/pkgslog/pkg":       slog.LevelDebug,
    "github.com/reugn/pkgslog/pkg/inner": slog.LevelInfo,
}
logger := slog.New(pkgslog.NewPackageHandler(textHandler, packageMap))

Benchmarking

Benchmark results compared to the standard slog.TextHandler

BenchmarkPkgSlog
BenchmarkPkgSlog-16       437230              2421 ns/op             232 B/op          2 allocs/op
BenchmarkSlog
BenchmarkSlog-16         1000000              1004 ns/op               0 B/op          0 allocs/op

License

Licensed under the MIT License.

About

A package level structured log/slog handler for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%