blob: 49490eaeb65862c20995de6317d81580c3797961 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# 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 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.
|