From cbd4c38f3dfa6a1af83acd2dbefb59fbda3e6ffe Mon Sep 17 00:00:00 2001 From: Lachlan Date: Tue, 11 Aug 2020 19:51:39 +1000 Subject: [PATCH] Issue #5121 - always use isDebugEnabled() check before debug logging in WebSocket (#5123) * Issue #5121 - always use isDebugEnabled() check before logging in CompressExtension Signed-off-by: Lachlan Roberts * Issue #5121 - always use isDebugEnabled() check before debug logging Signed-off-by: Lachlan Roberts * Issue #5121 - always use isDebugEnabled() check before debug logging in WebSocket Signed-off-by: Lachlan Roberts --- .../websocket/common/WebSocketSession.java | 3 ++- .../common/extensions/AbstractExtension.java | 6 +++-- .../common/extensions/ExtensionStack.java | 15 ++++++++---- .../compress/CompressExtension.java | 24 +++++-------------- .../compress/PerMessageDeflateExtension.java | 9 ++++--- .../fragment/FragmentExtension.java | 6 +++-- .../server/WebSocketUpgradeFilter.java | 6 +++-- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index d0d364608114..268961b7fec1 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -351,7 +351,8 @@ public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMo } catch (Throwable x) { - LOG.debug("Exception while notifying failure of callback " + callback, x); + if (LOG.isDebugEnabled()) + LOG.debug("Exception while notifying failure of callback " + callback, x); } return; } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java index db4eebc6ff8c..e4d704dde566 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java @@ -143,7 +143,8 @@ public boolean isRsv3User() protected void nextIncomingFrame(Frame frame) { - log.debug("nextIncomingFrame({})", frame); + if (log.isDebugEnabled()) + log.debug("nextIncomingFrame({})", frame); this.nextIncoming.incomingFrame(frame); } @@ -151,7 +152,8 @@ protected void nextOutgoingFrame(Frame frame, WriteCallback callback, BatchMode { try { - log.debug("nextOutgoingFrame({})", frame); + if (log.isDebugEnabled()) + log.debug("nextOutgoingFrame({})", frame); this.nextOutgoing.outgoingFrame(frame, callback, batchMode); } catch (Throwable t) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStack.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStack.java index 3b19467a1acd..d307e5b8617c 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStack.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/ExtensionStack.java @@ -230,17 +230,20 @@ public void negotiate(List configs) // Check RSV if (ext.isRsv1User() && (rsvClaims[0] != null)) { - LOG.debug("Not adding extension {}. Extension {} already claimed RSV1", config, rsvClaims[0]); + if (LOG.isDebugEnabled()) + LOG.debug("Not adding extension {}. Extension {} already claimed RSV1", config, rsvClaims[0]); continue; } if (ext.isRsv2User() && (rsvClaims[1] != null)) { - LOG.debug("Not adding extension {}. Extension {} already claimed RSV2", config, rsvClaims[1]); + if (LOG.isDebugEnabled()) + LOG.debug("Not adding extension {}. Extension {} already claimed RSV2", config, rsvClaims[1]); continue; } if (ext.isRsv3User() && (rsvClaims[2] != null)) { - LOG.debug("Not adding extension {}. Extension {} already claimed RSV3", config, rsvClaims[2]); + if (LOG.isDebugEnabled()) + LOG.debug("Not adding extension {}. Extension {} already claimed RSV3", config, rsvClaims[2]); continue; } @@ -445,7 +448,8 @@ private void notifyCallbackSuccess(WriteCallback callback) } catch (Throwable x) { - LOG.debug("Exception while notifying success of callback " + callback, x); + if (LOG.isDebugEnabled()) + LOG.debug("Exception while notifying success of callback " + callback, x); } } @@ -458,7 +462,8 @@ private void notifyCallbackFailure(WriteCallback callback, Throwable failure) } catch (Throwable x) { - LOG.debug("Exception while notifying failure of callback " + callback, x); + if (LOG.isDebugEnabled()) + LOG.debug("Exception while notifying failure of callback " + callback, x); } } } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java index 4a2bf9d5126b..6952ccb67ea0 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java @@ -193,7 +193,8 @@ protected void decompress(ByteAccumulator accumulator, ByteBuffer buf) throws Da { if (!supplyInput(inflater, buf)) { - LOG.debug("Needed input, but no buffer could supply input"); + if (LOG.isDebugEnabled()) + LOG.debug("Needed input, but no buffer could supply input"); return; } @@ -202,26 +203,22 @@ protected void decompress(ByteAccumulator accumulator, ByteBuffer buf) throws Da { if (read == 0) { - LOG.debug("Decompress: read 0 {}", toDetail(inflater)); + if (LOG.isDebugEnabled()) + LOG.debug("Decompress: read 0 {}", toDetail(inflater)); break; } else { // do something with output if (LOG.isDebugEnabled()) - { LOG.debug("Decompressed {} bytes: {}", read, toDetail(inflater)); - } - accumulator.copyChunk(output, 0, read); } } } if (LOG.isDebugEnabled()) - { LOG.debug("Decompress: exiting {}", toDetail(inflater)); - } } @Override @@ -293,9 +290,7 @@ private static boolean supplyInput(Inflater inflater, ByteBuffer buf) if (buf == null || buf.remaining() <= 0) { if (LOG.isDebugEnabled()) - { LOG.debug("No data left left to supply to Inflater"); - } return false; } @@ -322,9 +317,7 @@ private static boolean supplyInput(Inflater inflater, ByteBuffer buf) inflater.setInput(input, inputOffset, len); if (LOG.isDebugEnabled()) - { LOG.debug("Supplied {} input bytes: {}", input.length, toDetail(inflater)); - } return true; } @@ -333,9 +326,7 @@ private static boolean supplyInput(Deflater deflater, ByteBuffer buf) if (buf == null || buf.remaining() <= 0) { if (LOG.isDebugEnabled()) - { LOG.debug("No data left left to supply to Deflater"); - } return false; } @@ -362,9 +353,7 @@ private static boolean supplyInput(Deflater deflater, ByteBuffer buf) deflater.setInput(input, inputOffset, len); if (LOG.isDebugEnabled()) - { LOG.debug("Supplied {} input bytes: {}", input.length, toDetail(deflater)); - } return true; } @@ -462,7 +451,8 @@ protected Action process() throws Exception if (finished) { current = pollEntry(); - LOG.debug("Processing {}", current); + if (LOG.isDebugEnabled()) + LOG.debug("Processing {}", current); if (current == null) return Action.IDLE; deflate(current); @@ -570,9 +560,7 @@ else if (fin) } if (LOG.isDebugEnabled()) - { LOG.debug("Compressed {}: input:{} -> payload:{}", entry, outputLength, payload.remaining()); - } boolean continuation = frame.getType().isContinuation() || !first; DataFrame chunk = new DataFrame(frame, continuation); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtension.java index 931fe4ea1494..37482f8bd678 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtension.java @@ -105,7 +105,8 @@ protected void nextIncomingFrame(Frame frame) { if (frame.isFin() && !incomingContextTakeover) { - LOG.debug("Incoming Context Reset"); + if (LOG.isDebugEnabled()) + LOG.debug("Incoming Context Reset"); decompressCount.set(0); getInflater().reset(); } @@ -117,7 +118,8 @@ protected void nextOutgoingFrame(Frame frame, WriteCallback callback, BatchMode { if (frame.isFin() && !outgoingContextTakeover) { - LOG.debug("Outgoing Context Reset"); + if (LOG.isDebugEnabled()) + LOG.debug("Outgoing Context Reset"); getDeflater().reset(); } super.nextOutgoingFrame(frame, callback, batchMode); @@ -188,7 +190,8 @@ public void setConfig(final ExtensionConfig config) } } - LOG.debug("config: outgoingContextTakeover={}, incomingContextTakeover={} : {}", outgoingContextTakeover, incomingContextTakeover, this); + if (LOG.isDebugEnabled()) + LOG.debug("config: outgoingContextTakeover={}, incomingContextTakeover={} : {}", outgoingContextTakeover, incomingContextTakeover, this); super.setConfig(configNegotiated); } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java index e87eeda319e8..6830605b6a2a 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java @@ -130,10 +130,12 @@ protected Action process() current = pollEntry(); if (current == null) { - LOG.debug("Processing IDLE", current); + if (LOG.isDebugEnabled()) + LOG.debug("Processing IDLE", current); return Action.IDLE; } - LOG.debug("Processing {}", current); + if (LOG.isDebugEnabled()) + LOG.debug("Processing {}", current); fragment(current, true); } else diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java index 0815501025c4..6138423f1adf 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java @@ -200,7 +200,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if (configuration == null) { // no configuration, cannot operate - LOG.debug("WebSocketUpgradeFilter is not operational - missing " + NativeWebSocketConfiguration.class.getName()); + if (LOG.isDebugEnabled()) + LOG.debug("WebSocketUpgradeFilter is not operational - missing " + NativeWebSocketConfiguration.class.getName()); chain.doFilter(request, response); return; } @@ -210,7 +211,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if (factory == null) { // no factory, cannot operate - LOG.debug("WebSocketUpgradeFilter is not operational - no WebSocketServletFactory configured"); + if (LOG.isDebugEnabled()) + LOG.debug("WebSocketUpgradeFilter is not operational - no WebSocketServletFactory configured"); chain.doFilter(request, response); return; }