Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harwoeck/liblog
Discontinued in favor of log/slog. liblog was an interface/contract for logging backends. It was used by public libraries and packages that wanted to give their user's control over structured and leveled logging output.
https://github.com/harwoeck/liblog
apache2 apache2-license go golang libraries library log logging package packages user-control
Last synced: 1 day ago
JSON representation
Discontinued in favor of log/slog. liblog was an interface/contract for logging backends. It was used by public libraries and packages that wanted to give their user's control over structured and leveled logging output.
- Host: GitHub
- URL: https://github.com/harwoeck/liblog
- Owner: harwoeck
- License: apache-2.0
- Created: 2021-07-09T13:12:20.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-05T17:08:59.000Z (9 months ago)
- Last Synced: 2024-06-21T02:17:18.523Z (5 months ago)
- Topics: apache2, apache2-license, go, golang, libraries, library, log, logging, package, packages, user-control
- Language: Go
- Homepage: https://harwoeck.com
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# liblog
> [!CAUTION]
> **DISCONTINUED in favor of [log/slog](https://go.dev/blog/slog)***liblog* was an interface/contract for logging backends. It was used by public libraries and packages that wanted to give their user's control over structured and leveled logging output.
[![Go Reference](https://pkg.go.dev/badge/github.com/harwoeck/liblog.svg)](https://pkg.go.dev/github.com/harwoeck/liblog)
### Advantages
- 🟢 Users can provide their own logging stack __**and**__ get detailed package-level logging
- 🟢 *liblog* provides implementations for well-known logging backends (see `/impl`)### Getting started
- `go get github.com/harwoeck/liblog` - provides the *liblog* interface, and an implementation that only relies on Go's
standard library
- Use `liblog.NewStd(...StdOption)` by default inside your package, but give users the option to specify their own
logging implementation (`liblog.Logger`)### Usage
- Extensively use all provided options, like `Named()`, `With()` and appropriate logging levels, to provide the best log
results/experience.
- Use `field()` (or `liblog.NewField()`) to generate structured elements for your logs (see Tips #1)### Tips
1. Create a file `logfield.go` and add this `fieldImpl`. You can now use `field()` instead of the
longer `liblog.NewField()` inside your package to create structured logging elements
```go
type fieldImpl struct {
key string
value interface{}
}
func (f *fieldImpl) Key() string { return f.key }
func (f *fieldImpl) Value() interface{} { return f.value }
func field(key string, value interface{}) contract.Field {
return &fieldImpl{
key: key,
value: value,
}
}
```