Skip to content

Commit a55cd56

Browse files
committed
limit logging info to 10000 char maximum
1 parent 10ed92e commit a55cd56

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/gce-pd-csi-driver/utils.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import (
2828
)
2929

3030
const (
31-
fsTypeXFS = "xfs"
31+
fsTypeXFS = "xfs"
32+
maxLogChar = 10000
3233
)
3334

3435
var ProbeCSIFullMethod = "/csi.v1.Identity/Probe"
@@ -69,7 +70,11 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
6970
if err != nil {
7071
klog.Errorf("%s returned with error: %v", info.FullMethod, err)
7172
} else {
72-
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, resp)
73+
cappedStr := fmt.Sprintf("%v", resp)
74+
if len(cappedStr) > maxLogChar {
75+
cappedStr = cappedStr[:maxLogChar] + fmt.Sprintf(" [response body too large, log capped to %d chars]", maxLogChar)
76+
}
77+
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, cappedStr)
7378
}
7479
return resp, err
7580
}

0 commit comments

Comments
 (0)