forked from tommy351/zap-stackdriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
43 lines (38 loc) · 979 Bytes
/
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
package stackdriver_test
import (
"github.com/tommy351/zap-stackdriver"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func Example_basic() {
config := &zap.Config{
Level: zap.NewAtomicLevelAt(zapcore.InfoLevel),
Encoding: "json",
EncoderConfig: stackdriver.EncoderConfig,
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}
logger, err := config.Build(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return &stackdriver.Core{
Core: core,
}
}), zap.Fields(
stackdriver.LogServiceContext(&stackdriver.ServiceContext{
Service: "foo",
Version: "bar",
}),
))
if err != nil {
panic(err)
}
logger.Info("Hello",
stackdriver.LogUser("token"),
stackdriver.LogHTTPRequest(&stackdriver.HTTPRequest{
Method: "GET",
URL: "/foo",
UserAgent: "bar",
Referrer: "baz",
ResponseStatusCode: 200,
RemoteIP: "1.2.3.4",
}))
}