truncateBody decides if the body should be truncated, based on the glog Verbosity.
(body string)
| 917 | |
| 918 | // truncateBody decides if the body should be truncated, based on the glog Verbosity. |
| 919 | func truncateBody(body string) string { |
| 920 | max := 0 |
| 921 | switch { |
| 922 | case bool(klog.V(10)): |
| 923 | return body |
| 924 | case bool(klog.V(9)): |
| 925 | max = 10240 |
| 926 | case bool(klog.V(8)): |
| 927 | max = 1024 |
| 928 | } |
| 929 | |
| 930 | if len(body) <= max { |
| 931 | return body |
| 932 | } |
| 933 | |
| 934 | return body[:max] + fmt.Sprintf(" [truncated %d chars]", len(body)-max) |
| 935 | } |
| 936 | |
| 937 | // glogBody logs a body output that could be either JSON or protobuf. It explicitly guards against |
| 938 | // allocating a new string for the body output unless necessary. Uses a simple heuristic to determine |
no outgoing calls