From 8fd5fc671f19c483d03cf33b7fcea5e3d7797f62 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Thu, 6 Oct 2022 11:41:48 +0300 Subject: [PATCH] Ensure logs are prefixed with channel information when possible (#2529) --- .../channel/AbstractChannelMetricsHandler.java | 12 +++++++----- .../reactor/netty/transport/TransportConfig.java | 2 +- .../client/AbstractHttpClientMetricsHandler.java | 10 ++++++---- .../server/AbstractHttpServerMetricsHandler.java | 16 +++++++++------- 4 files changed, 23 insertions(+), 17 deletions(-) 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 98b8eac2eb..0afad61c88 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 @@ -28,6 +28,8 @@ import java.net.SocketAddress; +import static reactor.netty.ReactorNetty.format; + /** * Base {@link ChannelHandler} for collecting metrics on protocol level. * @@ -55,7 +57,7 @@ public void channelActive(ChannelHandlerContext ctx) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -71,7 +73,7 @@ public void channelInactive(ChannelHandlerContext ctx) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -116,7 +118,7 @@ else if (msg instanceof DatagramPacket) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -144,7 +146,7 @@ else if (msg instanceof DatagramPacket) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -160,7 +162,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "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/TransportConfig.java b/reactor-netty-core/src/main/java/reactor/netty/transport/TransportConfig.java index 0e02b5bd16..3f6bda7f46 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 @@ -389,7 +389,7 @@ else if (alloc instanceof UnpooledByteBufAllocator) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(channel, "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/client/AbstractHttpClientMetricsHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/client/AbstractHttpClientMetricsHandler.java index 31e475d39d..1bfb77a454 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 @@ -33,6 +33,8 @@ import java.time.Duration; import java.util.function.Function; +import static reactor.netty.ReactorNetty.format; + /** * @author Violeta Georgieva * @since 1.0.8 @@ -95,7 +97,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -104,7 +106,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -130,7 +132,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -144,7 +146,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "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 495fa0a09c..2caa56b540 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 @@ -33,6 +33,8 @@ import java.time.Duration; import java.util.function.Function; +import static reactor.netty.ReactorNetty.format; + /** * @author Violeta Georgieva * @since 1.0.8 @@ -74,7 +76,7 @@ public void channelActive(ChannelHandlerContext ctx) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -90,7 +92,7 @@ public void channelInactive(ChannelHandlerContext ctx) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -123,7 +125,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -140,7 +142,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -153,7 +155,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -194,7 +196,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem } @@ -214,7 +216,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { } catch (RuntimeException e) { if (log.isWarnEnabled()) { - log.warn("Exception caught while recording metrics.", e); + log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e); } // Allow request-response exchange to continue, unaffected by metrics problem }