Simplify two-args message formatter in LoggingHandler
This commit is contained in:
parent
4fcec8b87d
commit
0dddec8dfd
@ -336,20 +336,18 @@ public class LoggingHandler extends ChannelHandlerAdapter {
|
|||||||
* @param secondArg the second argument of the event
|
* @param secondArg the second argument of the event
|
||||||
*/
|
*/
|
||||||
protected String format(ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg) {
|
protected String format(ChannelHandlerContext ctx, String eventName, Object firstArg, Object secondArg) {
|
||||||
|
if (secondArg == null) {
|
||||||
|
return format(ctx, eventName, firstArg);
|
||||||
|
}
|
||||||
|
|
||||||
String chStr = ctx.channel().toString();
|
String chStr = ctx.channel().toString();
|
||||||
String arg1Str = String.valueOf(firstArg);
|
String arg1Str = String.valueOf(firstArg);
|
||||||
if (secondArg == null) {
|
|
||||||
StringBuilder buf = new StringBuilder(chStr.length() + 1 + eventName + 2 + arg1Str.length());
|
|
||||||
buf.append(chStr).append(' ').append(eventName).append(": ").append(arg1Str);
|
|
||||||
return buf.toString();
|
|
||||||
} else {
|
|
||||||
String arg2Str = secondArg.toString();
|
String arg2Str = secondArg.toString();
|
||||||
StringBuilder buf = new StringBuilder(
|
StringBuilder buf = new StringBuilder(
|
||||||
chStr.length() + 1 + eventName + 2 + arg1Str.length() + 2 + arg2Str.length());
|
chStr.length() + 1 + eventName + 2 + arg1Str.length() + 2 + arg2Str.length());
|
||||||
buf.append(chStr).append(' ').append(eventName).append(": ").append(arg1Str).append(", ").append(arg2Str);
|
buf.append(chStr).append(' ').append(eventName).append(": ").append(arg1Str).append(", ").append(arg2Str);
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the default log message of the specified event whose argument is a {@link ByteBuf}.
|
* Generates the default log message of the specified event whose argument is a {@link ByteBuf}.
|
||||||
|
Loading…
Reference in New Issue
Block a user