Simplify two-args message formatter in LoggingHandler

This commit is contained in:
Trustin Lee 2013-12-02 18:56:33 +09:00
parent 4fcec8b87d
commit 0dddec8dfd

View File

@ -336,19 +336,17 @@ public class LoggingHandler extends ChannelHandlerAdapter {
* @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();
}
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();
}
/**