Skip to content

Commit 6a22318

Browse files
authored
Merge pull request kubernetes-client#1817 from yue9944882/chore/http2-logging-option
Additional debugging option for printing http2 frames
2 parents 67bf288 + 62bb487 commit 6a22318

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.util.okhttp;
14+
15+
import java.util.logging.ConsoleHandler;
16+
import java.util.logging.Level;
17+
import java.util.logging.LogRecord;
18+
19+
class HTTP2ConsoleHandler extends ConsoleHandler {
20+
21+
public HTTP2ConsoleHandler() {
22+
setLevel(Level.FINE);
23+
setFormatter(new Formatter());
24+
}
25+
26+
public static class Formatter extends java.util.logging.Formatter {
27+
@Override
28+
public String format(LogRecord record) {
29+
return String.format("[%1$tF %1$tT] %2$s %n", record.getMillis(), record.getMessage());
30+
}
31+
}
32+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.util.okhttp;
14+
15+
import java.util.logging.Level;
16+
import java.util.logging.Logger;
17+
import okhttp3.internal.concurrent.TaskRunner;
18+
import okhttp3.internal.http2.Http2;
19+
20+
public class HTTP2Logging {
21+
22+
private static final HTTP2ConsoleHandler consoleHandler = new HTTP2ConsoleHandler();
23+
24+
private static boolean debuggingHTTP2 = false;
25+
private static final Logger http2Logger = Logger.getLogger(Http2.class.getName());
26+
27+
private static boolean debuggingTaskRunner = false;
28+
private static final Logger taskRunnerLogger = Logger.getLogger(TaskRunner.class.getName());
29+
30+
public static void enableHTTP2Logging(boolean enable) {
31+
if (debuggingHTTP2 == enable) {
32+
return;
33+
}
34+
if (enable) {
35+
http2Logger.addHandler(consoleHandler);
36+
http2Logger.setLevel(Level.FINEST);
37+
} else {
38+
http2Logger.removeHandler(consoleHandler);
39+
http2Logger.setLevel(Level.INFO);
40+
}
41+
debuggingHTTP2 = enable;
42+
}
43+
44+
public static void enableTaskRunnerLogging(boolean enable) {
45+
if (debuggingTaskRunner == enable) {
46+
return;
47+
}
48+
if (enable) {
49+
taskRunnerLogger.addHandler(consoleHandler);
50+
taskRunnerLogger.setLevel(Level.FINEST);
51+
} else {
52+
taskRunnerLogger.removeHandler(consoleHandler);
53+
taskRunnerLogger.setLevel(Level.INFO);
54+
}
55+
debuggingTaskRunner = enable;
56+
}
57+
}

0 commit comments

Comments
 (0)