Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hashicorp/logutils
Utilities for slightly better logging in Go (Golang).
https://github.com/hashicorp/logutils
Last synced: 6 days ago
JSON representation
Utilities for slightly better logging in Go (Golang).
- Host: GitHub
- URL: https://github.com/hashicorp/logutils
- Owner: hashicorp
- License: mpl-2.0
- Created: 2013-10-09T07:31:15.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-02-01T17:00:49.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T16:58:32.358Z (about 1 month ago)
- Language: Go
- Size: 14.6 KB
- Stars: 368
- Watchers: 304
- Forks: 35
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - logutils - Utilities for slightly better logging in Go (Golang) extending the standard logger. (Logging / Search and Analytic Databases)
- awesome-repositories - hashicorp/logutils - Utilities for slightly better logging in Go (Golang). (Go)
- awesome-go - logutils - Utilities for slightly better logging in Go (Golang). - ★ 228 (Logging)
- awesome-go-extra - logutils - 10-09T07:31:15Z|2021-11-08T05:38:47Z| (Logging / Advanced Console UIs)
- awesome-go-zh - logutils
README
# logutils
logutils is a Go package that augments the standard library "log" package
to make logging a bit more modern, without fragmenting the Go ecosystem
with new logging packages.## The simplest thing that could possibly work
Presumably your application already uses the default `log` package. To switch, you'll want your code to look like the following:
```go
package mainimport (
"log"
"os""github.com/hashicorp/logutils"
)func main() {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"DEBUG", "WARN", "ERROR"},
MinLevel: logutils.LogLevel("WARN"),
Writer: os.Stderr,
}
log.SetOutput(filter)log.Print("[DEBUG] Debugging") // this will not print
log.Print("[WARN] Warning") // this will
log.Print("[ERROR] Erring") // and so will this
log.Print("Message I haven't updated") // and so will this
}
```This logs to standard error exactly like go's standard logger. Any log messages you haven't converted to have a level will continue to print as before.