-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
40 lines (31 loc) · 1.08 KB
/
example_test.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
package zapctxd_test
import (
"context"
"github.com/bool64/ctxd"
"github.com/bool64/zapctxd"
"go.uber.org/zap"
)
func ExampleNew() {
logger := zapctxd.New(zapctxd.Config{
Level: zap.WarnLevel,
DevMode: true,
StripTime: true,
})
ctx := ctxd.AddFields(context.Background(),
"foo", "bar",
)
logger.Info(ctx, "not logged due to WARN level config")
logger.Error(ctx, "something failed",
"baz", 1,
"quux", 2.2,
)
logger.Important(ctx, "logged because is important")
logger.Info(ctxd.WithDebug(ctx), "logged because of forced DEBUG mode")
logger.AtomicLevel.SetLevel(zap.DebugLevel)
logger.Info(ctx, "logged because logger level was changed to DEBUG")
// Output:
// <stripped> ERROR zapctxd/example_test.go:24 something failed {"baz": 1, "quux": 2.2, "foo": "bar"}
// <stripped> INFO zapctxd/example_test.go:29 logged because is important {"foo": "bar"}
// <stripped> INFO zapctxd/example_test.go:30 logged because of forced DEBUG mode {"foo": "bar"}
// <stripped> INFO zapctxd/example_test.go:33 logged because logger level was changed to DEBUG {"foo": "bar"}
}