diff --git a/reactor-netty-core/src/main/java/reactor/netty/channel/AbstractChannelMetricsHandler.java b/reactor-netty-core/src/main/java/reactor/netty/channel/AbstractChannelMetricsHandler.java index 13213cc432..98b8eac2eb 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/channel/AbstractChannelMetricsHandler.java +++ b/reactor-netty-core/src/main/java/reactor/netty/channel/AbstractChannelMetricsHandler.java @@ -54,7 +54,9 @@ public void channelActive(ChannelHandlerContext ctx) { recorder().recordServerConnectionOpened(ctx.channel().localAddress()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } @@ -68,7 +70,9 @@ public void channelInactive(ChannelHandlerContext ctx) { recorder().recordServerConnectionClosed(ctx.channel().localAddress()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } @@ -111,7 +115,9 @@ else if (msg instanceof DatagramPacket) { } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -137,7 +143,9 @@ else if (msg instanceof DatagramPacket) { } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -151,7 +159,9 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { recordException(ctx, remoteAddress != null ? remoteAddress : ctx.channel().remoteAddress()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } diff --git a/reactor-netty-core/src/main/java/reactor/netty/resources/PooledConnectionProvider.java b/reactor-netty-core/src/main/java/reactor/netty/resources/PooledConnectionProvider.java index 7bbb295cb9..48da14061b 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/resources/PooledConnectionProvider.java +++ b/reactor-netty-core/src/main/java/reactor/netty/resources/PooledConnectionProvider.java @@ -348,8 +348,10 @@ protected static final class PoolFactory { Double.parseDouble(System.getProperty(ReactorNetty.POOL_GET_PERMITS_SAMPLING_RATE, "0")); if (getPermitsSamplingRate > 1d) { DEFAULT_POOL_GET_PERMITS_SAMPLING_RATE = 0; - log.warn("Invalid configuration [" + ReactorNetty.POOL_GET_PERMITS_SAMPLING_RATE + "=" + getPermitsSamplingRate + - "], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy in not enabled."); + if (log.isWarnEnabled()) { + log.warn("Invalid configuration [" + ReactorNetty.POOL_GET_PERMITS_SAMPLING_RATE + "=" + getPermitsSamplingRate + + "], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy in not enabled."); + } } else { DEFAULT_POOL_GET_PERMITS_SAMPLING_RATE = getPermitsSamplingRate; @@ -362,8 +364,10 @@ protected static final class PoolFactory { Double.parseDouble(System.getProperty(ReactorNetty.POOL_RETURN_PERMITS_SAMPLING_RATE, "0")); if (returnPermitsSamplingRate > 1d) { DEFAULT_POOL_RETURN_PERMITS_SAMPLING_RATE = 0; - log.warn("Invalid configuration [" + ReactorNetty.POOL_RETURN_PERMITS_SAMPLING_RATE + "=" + returnPermitsSamplingRate + - "], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy is enabled."); + if (log.isWarnEnabled()) { + log.warn("Invalid configuration [" + ReactorNetty.POOL_RETURN_PERMITS_SAMPLING_RATE + "=" + returnPermitsSamplingRate + + "], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy is enabled."); + } } else { DEFAULT_POOL_RETURN_PERMITS_SAMPLING_RATE = returnPermitsSamplingRate; diff --git a/reactor-netty-core/src/main/java/reactor/netty/transport/AddressResolverGroupMetrics.java b/reactor-netty-core/src/main/java/reactor/netty/transport/AddressResolverGroupMetrics.java index 169a5a4c5f..a5b2dea05d 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/transport/AddressResolverGroupMetrics.java +++ b/reactor-netty-core/src/main/java/reactor/netty/transport/AddressResolverGroupMetrics.java @@ -136,7 +136,9 @@ void record(long resolveTimeStart, String status, SocketAddress remoteAddress) { status); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } diff --git a/reactor-netty-core/src/main/java/reactor/netty/transport/ServerTransport.java b/reactor-netty-core/src/main/java/reactor/netty/transport/ServerTransport.java index ec5c2af63b..52fe15890a 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/transport/ServerTransport.java +++ b/reactor-netty-core/src/main/java/reactor/netty/transport/ServerTransport.java @@ -400,7 +400,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { .eventLoop() .schedule(enableAutoReadTask, 1, TimeUnit.SECONDS) .addListener(future -> { - if (!future.isSuccess()) { + if (!future.isSuccess() && log.isDebugEnabled()) { log.debug(format(ctx.channel(), "Cannot enable auto-read"), future.cause()); } }); @@ -419,7 +419,9 @@ void enableAutoReadTask(Channel channel) { static void forceClose(Channel child, Throwable t) { child.unsafe().closeForcibly(); - log.warn(format(child, "Failed to register an accepted channel: {}"), child, t); + if (log.isWarnEnabled()) { + log.warn(format(child, "Failed to register an accepted channel: {}"), child, t); + } } } diff --git a/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConfig.java b/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConfig.java index 99d1da372c..6765400729 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConfig.java +++ b/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConfig.java @@ -388,7 +388,9 @@ else if (alloc instanceof UnpooledByteBufAllocator) { MicrometerEventLoopMeterRegistrar.INSTANCE.registerMetrics(channel.eventLoop()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } diff --git a/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConnector.java b/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConnector.java index 4b1b097121..c27a76410e 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConnector.java +++ b/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConnector.java @@ -204,12 +204,16 @@ static void setChannelOptions(Channel channel, Map, ?> options, } try { if (!channel.config().setOption((ChannelOption) e.getKey(), e.getValue())) { - log.warn(format(channel, "Unknown channel option '{}' for channel '{}'"), e.getKey(), channel); + if (log.isWarnEnabled()) { + log.warn(format(channel, "Unknown channel option '{}' for channel '{}'"), e.getKey(), channel); + } } } catch (Throwable t) { - log.warn(format(channel, "Failed to set channel option '{}' with value '{}' for channel '{}'"), - e.getKey(), e.getValue(), channel, t); + if (log.isWarnEnabled()) { + log.warn(format(channel, "Failed to set channel option '{}' with value '{}' for channel '{}'"), + e.getKey(), e.getValue(), channel, t); + } } } } diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java b/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java index c16c337637..d5d27bf568 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/HttpOperations.java @@ -120,8 +120,10 @@ public NettyOutbound send(Publisher source) { return Mono.error(e); } if (HttpUtil.getContentLength(outboundHttpMessage(), -1) == 0) { - log.debug(format(channel(), "Dropped HTTP content, " + - "since response has Content-Length: 0 {}"), toPrettyHexDump(msg)); + if (log.isDebugEnabled()) { + log.debug(format(channel(), "Dropped HTTP content, " + + "since response has Content-Length: 0 {}"), toPrettyHexDump(msg)); + } msg.release(); return FutureMono.from(channel().writeAndFlush(newFullBodyMessage(Unpooled.EMPTY_BUFFER))); } @@ -154,8 +156,10 @@ public NettyOutbound sendObject(Object message) { throw e; } if (HttpUtil.getContentLength(outboundHttpMessage(), -1) == 0) { - log.debug(format(channel(), "Dropped HTTP content, " + - "since response has Content-Length: 0 {}"), toPrettyHexDump(b)); + if (log.isDebugEnabled()) { + log.debug(format(channel(), "Dropped HTTP content, " + + "since response has Content-Length: 0 {}"), toPrettyHexDump(b)); + } b.release(); return channel().writeAndFlush(newFullBodyMessage(Unpooled.EMPTY_BUFFER)); } diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/client/AbstractHttpClientMetricsHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/client/AbstractHttpClientMetricsHandler.java index b30db4832a..8398300b6b 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/client/AbstractHttpClientMetricsHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/client/AbstractHttpClientMetricsHandler.java @@ -95,14 +95,18 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) recordWrite(address); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } }); } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -127,7 +131,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -140,7 +146,9 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { recordException(ctx); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java index f70cd40be8..b931bb094b 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/AbstractHttpServerMetricsHandler.java @@ -73,7 +73,9 @@ public void channelActive(ChannelHandlerContext ctx) { recorder().recordServerConnectionOpened(ctx.channel().localAddress()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } @@ -87,7 +89,9 @@ public void channelInactive(ChannelHandlerContext ctx) { recorder().recordServerConnectionClosed(ctx.channel().localAddress()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } @@ -125,7 +129,9 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) ops.method().name(), ops.status().codeAsText().toString()); } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } // ops.hostAddress() == null when request decoding failed, in this case @@ -140,7 +146,9 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } } @@ -151,7 +159,9 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } finally { @@ -190,7 +200,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -208,7 +220,9 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { } } catch (RuntimeException e) { - log.warn("Exception caught while recording metrics.", e); + if (log.isWarnEnabled()) { + log.warn("Exception caught while recording metrics.", e); + } // Allow request-response exchange to continue, unaffected by metrics problem } diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/WebsocketServerOperations.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/WebsocketServerOperations.java index a35fa2f3e8..cac8744394 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/WebsocketServerOperations.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/WebsocketServerOperations.java @@ -123,7 +123,7 @@ final class WebsocketServerOperations extends HttpServerOperations // This change is needed after the Netty change https://github.com/netty/netty/pull/11966 channel.read(); } - else { + else if (log.isDebugEnabled()) { log.debug(format(channel, "Cannot bind WebsocketServerOperations after the handshake.")); } });