client: update gRPC logging to ignore stdout and stderr outputs

This commit is contained in:
Hakan Sariman
2025-03-27 22:57:17 +08:00
parent 8ba08cfaa3
commit 719fdbfe2d

View File

@@ -23,9 +23,10 @@ func UnaryClientInterceptor() grpc.UnaryClientInterceptor {
) error { ) error {
start := time.Now() start := time.Now()
isStdout := log.StandardLogger().Out == os.Stdout // don't log if log output is not a file
ignoreLog := log.StandardLogger().Out == os.Stdout || log.StandardLogger().Out == os.Stderr
if !isStdout { if !ignoreLog {
// log the request // log the request
if msg, ok := req.(proto.Message); ok { if msg, ok := req.(proto.Message); ok {
if jsonReq, err := protojson.Marshal(msg); err == nil { if jsonReq, err := protojson.Marshal(msg); err == nil {
@@ -43,7 +44,7 @@ func UnaryClientInterceptor() grpc.UnaryClientInterceptor {
duration := time.Since(start) duration := time.Since(start)
// log the response // log the response
if !isStdout { if !ignoreLog {
if err != nil { if err != nil {
log.Errorf("gRPC request failed: method=%s, duration=%v, error=%v", method, duration, err) log.Errorf("gRPC request failed: method=%s, duration=%v, error=%v", method, duration, err)
} else { } else {