@@ -89,19 +89,20 @@ func (c *clientPayloadReporter) PostMsgReceive(reply interface{}, err error, dur
89
89
}
90
90
91
91
type payloadReportable struct {
92
- clientDecider ClientPayloadLoggingDecider
93
- serverDecider ServerPayloadLoggingDecider
94
- logger Logger
92
+ clientDecider ClientPayloadLoggingDecider
93
+ serverDecider ServerPayloadLoggingDecider
94
+ logger Logger
95
+ timestampFormat string
95
96
}
96
97
97
98
func (r * payloadReportable ) ServerReporter (ctx context.Context , req interface {}, typ interceptors.GRPCType , service string , method string ) (interceptors.Reporter , context.Context ) {
98
99
if ! r .serverDecider (ctx , interceptors .FullMethod (service , method ), req ) {
99
100
return interceptors.NoopReporter {}, ctx
100
101
}
101
102
fields := commonFields (KindServerFieldValue , typ , service , method )
102
- fields = append (fields , "grpc.start_time" , time .Now ().Format (time . RFC3339 ))
103
+ fields = append (fields , "grpc.start_time" , time .Now ().Format (r . timestampFormat ))
103
104
if d , ok := ctx .Deadline (); ok {
104
- fields = append (fields , "grpc.request.deadline" , d .Format (time . RFC3339 ))
105
+ fields = append (fields , "grpc.request.deadline" , d .Format (r . timestampFormat ))
105
106
}
106
107
return & serverPayloadReporter {
107
108
ctx : ctx ,
@@ -113,9 +114,9 @@ func (r *payloadReportable) ClientReporter(ctx context.Context, _ interface{}, t
113
114
return interceptors.NoopReporter {}, ctx
114
115
}
115
116
fields := commonFields (KindClientFieldValue , typ , service , method )
116
- fields = append (fields , "grpc.start_time" , time .Now ().Format (time . RFC3339 ))
117
+ fields = append (fields , "grpc.start_time" , time .Now ().Format (r . timestampFormat ))
117
118
if d , ok := ctx .Deadline (); ok {
118
- fields = append (fields , "grpc.request.deadline" , d .Format (time . RFC3339 ))
119
+ fields = append (fields , "grpc.request.deadline" , d .Format (r . timestampFormat ))
119
120
}
120
121
return & clientPayloadReporter {
121
122
ctx : ctx ,
@@ -125,26 +126,26 @@ func (r *payloadReportable) ClientReporter(ctx context.Context, _ interface{}, t
125
126
126
127
// PayloadUnaryServerInterceptor returns a new unary server interceptors that logs the payloads of requests on INFO level.
127
128
// Logger tags will be used from tags context.
128
- func PayloadUnaryServerInterceptor (logger Logger , decider ServerPayloadLoggingDecider ) grpc.UnaryServerInterceptor {
129
- return interceptors .UnaryServerInterceptor (& payloadReportable {logger : logger , serverDecider : decider })
129
+ func PayloadUnaryServerInterceptor (logger Logger , decider ServerPayloadLoggingDecider , timestampFormat string ) grpc.UnaryServerInterceptor {
130
+ return interceptors .UnaryServerInterceptor (& payloadReportable {logger : logger , serverDecider : decider , timestampFormat : timestampFormat })
130
131
}
131
132
132
133
// PayloadStreamServerInterceptor returns a new server server interceptors that logs the payloads of requests on INFO level.
133
134
// Logger tags will be used from tags context.
134
- func PayloadStreamServerInterceptor (logger Logger , decider ServerPayloadLoggingDecider ) grpc.StreamServerInterceptor {
135
- return interceptors .StreamServerInterceptor (& payloadReportable {logger : logger , serverDecider : decider })
135
+ func PayloadStreamServerInterceptor (logger Logger , decider ServerPayloadLoggingDecider , timestampFormat string ) grpc.StreamServerInterceptor {
136
+ return interceptors .StreamServerInterceptor (& payloadReportable {logger : logger , serverDecider : decider , timestampFormat : timestampFormat })
136
137
}
137
138
138
- // PayloadUnaryClientInterceptor returns a new unary client interceptor that logs the paylods of requests and responses on INFO level.
139
+ // PayloadUnaryClientInterceptor returns a new unary client interceptor that logs the payloads of requests and responses on INFO level.
139
140
// Logger tags will be used from tags context.
140
- func PayloadUnaryClientInterceptor (logger Logger , decider ClientPayloadLoggingDecider ) grpc.UnaryClientInterceptor {
141
- return interceptors .UnaryClientInterceptor (& payloadReportable {logger : logger , clientDecider : decider })
141
+ func PayloadUnaryClientInterceptor (logger Logger , decider ClientPayloadLoggingDecider , timestampFormat string ) grpc.UnaryClientInterceptor {
142
+ return interceptors .UnaryClientInterceptor (& payloadReportable {logger : logger , clientDecider : decider , timestampFormat : timestampFormat })
142
143
}
143
144
144
145
// PayloadStreamClientInterceptor returns a new streaming client interceptor that logs the paylods of requests and responses on INFO level.
145
146
// Logger tags will be used from tags context.
146
- func PayloadStreamClientInterceptor (logger Logger , decider ClientPayloadLoggingDecider ) grpc.StreamClientInterceptor {
147
- return interceptors .StreamClientInterceptor (& payloadReportable {logger : logger , clientDecider : decider })
147
+ func PayloadStreamClientInterceptor (logger Logger , decider ClientPayloadLoggingDecider , timestampFormat string ) grpc.StreamClientInterceptor {
148
+ return interceptors .StreamClientInterceptor (& payloadReportable {logger : logger , clientDecider : decider , timestampFormat : timestampFormat })
148
149
}
149
150
150
151
func logProtoMessageAsJson (logger Logger , pbMsg proto.Message , key string , msg string ) {
0 commit comments