Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reugn/pkgslog
A package level structured log/slog handler for Go
https://github.com/reugn/pkgslog
go golang log log-level logger logger-middleware package-level slog structured-logging
Last synced: 3 days ago
JSON representation
A package level structured log/slog handler for Go
- Host: GitHub
- URL: https://github.com/reugn/pkgslog
- Owner: reugn
- License: mit
- Created: 2023-08-10T14:26:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-08T09:09:37.000Z (11 months ago)
- Last Synced: 2024-11-16T10:17:08.443Z (2 months ago)
- Topics: go, golang, log, log-level, logger, logger-middleware, package-level, slog, structured-logging
- Language: Go
- Homepage: https://pkg.go.dev/github.com/reugn/pkgslog
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pkgslog
[![Build](https://github.com/reugn/pkgslog/actions/workflows/build.yml/badge.svg)](https://github.com/reugn/pkgslog/actions/workflows/build.yml)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/reugn/pkgslog)](https://pkg.go.dev/github.com/reugn/pkgslog)
[![Go Report Card](https://goreportcard.com/badge/github.com/reugn/pkgslog)](https://goreportcard.com/report/github.com/reugn/pkgslog)
[![codecov](https://codecov.io/gh/reugn/pkgslog/branch/main/graph/badge.svg)](https://codecov.io/gh/reugn/pkgslog)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
```go
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.