forked from bombsimon/logrusr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
53 lines (41 loc) · 1.35 KB
/
main.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"errors"
"fmt"
"github.com/bombsimon/logrusr/v2"
"github.com/sirupsen/logrus"
)
func main() {
logrusLog := logrus.New()
log := logrusr.New(logrusLog)
log = log.WithName("MyName").WithValues("user", "you")
log.Info("hello", "val1", 1, "val2", map[string]int{"k": 1})
log.V(0).Info("you should see this")
log.V(2).Info("you should NOT see this")
log.Error(nil, "uh oh", "trouble", true, "reasons", []float64{0.1, 0.11, 3.14})
log.Error(errors.New("caught error"), "goodbye", "code", -1)
fmt.Println("")
entryLog := logrus.New().WithFields(logrus.Fields{
"some_field": "some_value",
"another_field": 42,
})
log = logrusr.New(entryLog)
log = log.WithName("MyName").WithValues("user", "you")
log.Info("hello", "val1", 1, "val2", map[string]int{"k": 1})
log.V(0).Info("you should see this")
log.V(2).Info("you should NOT see this")
log.Error(nil, "uh oh", "trouble", true, "reasons", []float64{0.1, 0.11, 3.14})
log.Error(errors.New("caught error"), "goodbye", "code", -1)
fmt.Println("")
log = log.WithName("subpackage")
log.Info("hello from subpackage")
log.WithName("even_deeper").Info("hello even deeper")
fmt.Println("")
logrusLog = logrus.New()
logrusLog.SetLevel(logrus.TraceLevel)
log = logrusr.New(
logrusLog,
logrusr.WithReportCaller(),
).WithCallDepth(0)
log.V(2).Info("NOW you should see this")
}