Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b4304f8e
Commit
b4304f8e
authored
Sep 14, 2017
by
Antoine Pelisse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client-go: Truncate body based on Verbosity level
parent
5d995e3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
request.go
staging/src/k8s.io/client-go/rest/request.go
+19
-2
No files found.
staging/src/k8s.io/client-go/rest/request.go
View file @
b4304f8e
...
...
@@ -823,6 +823,23 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
}
}
// truncateBody decides if the body should be truncated, based on the glog Verbosity.
func
truncateBody
(
body
string
)
string
{
max
:=
0
switch
{
case
bool
(
glog
.
V
(
9
))
:
max
=
10240
case
bool
(
glog
.
V
(
8
))
:
max
=
1024
}
if
len
(
body
)
<=
max
{
return
body
}
return
body
[
:
max
]
+
fmt
.
Sprintf
(
" [truncated %d chars]"
,
len
(
body
)
-
max
)
}
// glogBody logs a body output that could be either JSON or protobuf. It explicitly guards against
// allocating a new string for the body output unless necessary. Uses a simple heuristic to determine
// whether the body is printable.
...
...
@@ -831,9 +848,9 @@ func glogBody(prefix string, body []byte) {
if
bytes
.
IndexFunc
(
body
,
func
(
r
rune
)
bool
{
return
r
<
0x0a
})
!=
-
1
{
glog
.
Infof
(
"%s:
\n
%s"
,
prefix
,
hex
.
Dump
(
body
))
glog
.
Infof
(
"%s:
\n
%s"
,
prefix
,
truncateBody
(
hex
.
Dump
(
body
)
))
}
else
{
glog
.
Infof
(
"%s: %s"
,
prefix
,
string
(
body
))
glog
.
Infof
(
"%s: %s"
,
prefix
,
truncateBody
(
string
(
body
)
))
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment