Simplify two-args message formatter in LoggingHandler

This commit is contained in:
Trustin Lee 2013-12-02 18:56:33 +09:00
parent 2e58497160
commit a9150ee7d6

View File

@ -341,20 +341,18 @@ public class LoggingHandler extends ChannelDuplexHandler {
* @param secondArg the second argument of the event
*/
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 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();
StringBuilder buf = new StringBuilder(
chStr.length() + 1 + eventName + 2 + arg1Str.length() + 2 + arg2Str.length());
buf.append(chStr).append(' ').append(eventName).append(": ").append(arg1Str).append(", ").append(arg2Str);
return buf.toString();
}
}
/**
* Generates the default log message of the specified event whose argument is a {@link ByteBuf}.