@@ -6,12 +6,12 @@ package logr_test
6
6
import (
7
7
"context"
8
8
"testing"
9
+ "time"
9
10
10
11
grpclogr "github.com/grpc-ecosystem/go-grpc-middleware/providers/logr/v2"
11
12
"google.golang.org/grpc"
12
13
"k8s.io/klog/v2"
13
14
14
- middleware "github.com/grpc-ecosystem/go-grpc-middleware/v2"
15
15
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
16
16
)
17
17
@@ -29,10 +29,10 @@ func Example_initializationWithCustomLevels() {
29
29
}
30
30
// Create a server, make sure we put the tags context before everything else.
31
31
_ = grpc .NewServer (
32
- middleware . WithUnaryServerChain (
32
+ grpc . ChainUnaryInterceptor (
33
33
logging .UnaryServerInterceptor (grpclogr .InterceptorLogger (logger ), opts ... ),
34
34
),
35
- middleware . WithStreamServerChain (
35
+ grpc . ChainStreamInterceptor (
36
36
logging .StreamServerInterceptor (grpclogr .InterceptorLogger (logger ), opts ... ),
37
37
),
38
38
)
@@ -47,10 +47,10 @@ func Example_initializationWithDurationFieldOverride() {
47
47
}
48
48
// Create a server, make sure we put the tags context before everything else.
49
49
_ = grpc .NewServer (
50
- middleware . WithUnaryServerChain (
50
+ grpc . ChainUnaryInterceptor (
51
51
logging .UnaryServerInterceptor (grpclogr .InterceptorLogger (logger ), opts ... ),
52
52
),
53
- middleware . WithStreamServerChain (
53
+ grpc . ChainStreamInterceptor (
54
54
logging .StreamServerInterceptor (grpclogr .InterceptorLogger (logger ), opts ... ),
55
55
),
56
56
)
@@ -61,7 +61,7 @@ func ExampleWithDecider() {
61
61
logger := klog .NewKlogr ()
62
62
// Shared options for the logger, with a custom decider that log everything except successful calls from "/blah.foo.healthcheck/Check" method.
63
63
opts := []logging.Option {
64
- logging .WithDecider (func (methodFullName string ) logging.Decision {
64
+ logging .WithDecider (func (methodFullName string , _ error ) logging.Decision {
65
65
// will not log gRPC calls if it was a call to healthcheck and no error was raised
66
66
if methodFullName == "/blah.foo.healthcheck/Check" {
67
67
return logging .NoLogCall
@@ -73,10 +73,10 @@ func ExampleWithDecider() {
73
73
}
74
74
// Create a server, make sure we put the tags context before everything else.
75
75
_ = []grpc.ServerOption {
76
- middleware . WithUnaryServerChain (
76
+ grpc . ChainUnaryInterceptor (
77
77
logging .UnaryServerInterceptor (grpclogr .InterceptorLogger (logger ), opts ... ),
78
78
),
79
- middleware . WithStreamServerChain (
79
+ grpc . ChainStreamInterceptor (
80
80
logging .StreamServerInterceptor (grpclogr .InterceptorLogger (logger ), opts ... ),
81
81
),
82
82
}
@@ -86,19 +86,22 @@ func ExampleServerPayloadLoggingDecider() {
86
86
// Logger is used, allowing pre-definition of certain fields by the user.
87
87
logger := klog .NewKlogr ()
88
88
// Expect payload from "/blah.foo.healthcheck/Check" call to be logged.
89
- payloadDecider := func (ctx context.Context , fullMethodName string , servingObject interface {}) bool {
90
- return fullMethodName == "/blah.foo.healthcheck/Check"
89
+ payloadDecider := func (ctx context.Context , fullMethodName string , servingObject interface {}) logging.PayloadDecision {
90
+ if fullMethodName == "/blah.foo.healthcheck/Check" {
91
+ return logging .LogPayloadRequestAndResponse
92
+ }
93
+ return logging .NoPayloadLogging
91
94
}
92
95
93
96
// Create a server, make sure we put the tags context before everything else.
94
97
_ = []grpc.ServerOption {
95
- middleware . WithUnaryServerChain (
98
+ grpc . ChainUnaryInterceptor (
96
99
logging .UnaryServerInterceptor (grpclogr .InterceptorLogger (logger )),
97
- logging .PayloadUnaryServerInterceptor (grpclogr .InterceptorLogger (logger ), payloadDecider ),
100
+ logging .PayloadUnaryServerInterceptor (grpclogr .InterceptorLogger (logger ), payloadDecider , time . RFC3339 ),
98
101
),
99
- middleware . WithStreamServerChain (
102
+ grpc . ChainStreamInterceptor (
100
103
logging .StreamServerInterceptor (grpclogr .InterceptorLogger (logger )),
101
- logging .PayloadStreamServerInterceptor (grpclogr .InterceptorLogger (logger ), payloadDecider ),
104
+ logging .PayloadStreamServerInterceptor (grpclogr .InterceptorLogger (logger ), payloadDecider , time . RFC3339 ),
102
105
),
103
106
}
104
107
}
0 commit comments