|
| 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