forked from trpc-group/trpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
49 lines (44 loc) · 1.75 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
41
42
43
44
45
46
47
48
49
// Tencent is pleased to support the open source community by making tRPC available.
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
// If you have downloaded a copy of the tRPC source code from Tencent,
// please note that tRPC source code is licensed under the Apache 2.0 License that can be found in the LICENSE file.
package log_test
import "trpc.group/trpc-go/trpc-go/log"
func Example() {
l := log.NewZapLog([]log.OutputConfig{
{
Writer: "console",
Level: "debug",
Formatter: "console",
FormatConfig: log.FormatConfig{TimeFmt: "xxx"},
},
})
const defaultLoggerName = "default"
oldDefaultLogger := log.GetDefaultLogger()
log.Register(defaultLoggerName, l)
defer func() {
log.Register(defaultLoggerName, oldDefaultLogger)
}()
l = log.With(log.Field{Key: "tRPC-Go", Value: "log"})
l.Trace("hello world")
l.Debug("hello world")
l.Info("hello world")
l.Warn("hello world")
l.Error("hello world")
l.Tracef("hello world")
l.Debugf("hello world")
l.Infof("hello world")
l.Warnf("hello world")
l.Errorf("hello world")
// Output:
// xxx DEBUG log/example_test.go:27 hello world {"tRPC-Go": "log"}
// xxx DEBUG log/example_test.go:28 hello world {"tRPC-Go": "log"}
// xxx INFO log/example_test.go:29 hello world {"tRPC-Go": "log"}
// xxx WARN log/example_test.go:30 hello world {"tRPC-Go": "log"}
// xxx ERROR log/example_test.go:31 hello world {"tRPC-Go": "log"}
// xxx DEBUG log/example_test.go:32 hello world {"tRPC-Go": "log"}
// xxx DEBUG log/example_test.go:33 hello world {"tRPC-Go": "log"}
// xxx INFO log/example_test.go:34 hello world {"tRPC-Go": "log"}
// xxx WARN log/example_test.go:35 hello world {"tRPC-Go": "log"}
// xxx ERROR log/example_test.go:36 hello world {"tRPC-Go": "log"}
}