Fixes a LoggingHandler#format method with two arguments

Motivation:
Bug in capacity calculation: occurs auto convert to string instead of sum up.

Modifications:
Use `eventName.length()` in sum.

Result:
Less trash in logs.
This commit is contained in:
Nikolay Fedorovskikh 2017-10-24 00:53:31 +05:00 committed by Norman Maurer
parent 521e87984d
commit dcc39e5b21
2 changed files with 3 additions and 3 deletions

View File

@ -312,7 +312,7 @@ public class LoggingHandler extends ChannelDuplexHandler {
String arg1Str = String.valueOf(firstArg);
String arg2Str = secondArg.toString();
StringBuilder buf = new StringBuilder(
chStr.length() + 1 + eventName + 2 + arg1Str.length() + 2 + arg2Str.length());
chStr.length() + 1 + eventName.length() + 2 + arg1Str.length() + 2 + arg2Str.length());
buf.append(chStr).append(' ').append(eventName).append(": ").append(arg1Str).append(", ").append(arg2Str);
return buf.toString();
}

View File

@ -146,8 +146,8 @@ public class LoggingHandlerTest {
public void shouldLogChannelConnectWithLocalAddress() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
channel.connect(new InetSocketAddress(80), new InetSocketAddress(81)).await();
verify(appender).doAppend(argThat(
new RegexLogMatcher(".+CONNECT: 0.0.0.0/0.0.0.0:80, 0.0.0.0/0.0.0.0:81$")));
verify(appender).doAppend(argThat(new RegexLogMatcher(
"^\\[id: 0xembedded, L:embedded - R:embedded\\] CONNECT: 0.0.0.0/0.0.0.0:80, 0.0.0.0/0.0.0.0:81$")));
}
@Test