logutils
Utilities for slightly better logging in Go (Golang) extending the standard logger
About logutils
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:
package main
import (
"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.
Frequently Asked Questions
What is logutils?
logutils is a Logging library for the Go programming language. Utilities for slightly better logging in Go (Golang) extending the standard logger
How do I install logutils?
Install logutils with the Go module system using `go get hashicorp/logutils`. Check the repository for the current installation instructions.
What category does logutils belong to?
logutils is listed under Logging, specifically Logging.