Skip to content

reugn/pkgslog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pkgslog

Build PkgGoDev Go Report Card codecov

A structured log handler for log/slog that can be configured at the package level.
pkgslog allows you to set the minimum log level requirement for each package in your application.

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

Benchmarks

Benchmark results compared to the standard slog.TextHandler

BenchmarkPkgSlog-16       590906              2029 ns/op             232 B/op          2 allocs/op
BenchmarkSlog-16         1733892               701.6 ns/op             0 B/op          0 allocs/op

License

Licensed under the MIT License.