Skip to content

Commit

Permalink
Ensure logs are prefixed with channel information when possible (#2529)
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Oct 6, 2022
1 parent 9662c6f commit 8fd5fc6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Expand Up @@ -28,6 +28,8 @@

import java.net.SocketAddress;

import static reactor.netty.ReactorNetty.format;

/**
* Base {@link ChannelHandler} for collecting metrics on protocol level.
*
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
Expand Up @@ -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
}
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 8fd5fc6

Please sign in to comment.