Do not use String.format() for log message generation

- It's slow.
This commit is contained in:
Trustin Lee 2014-02-13 19:31:17 -08:00
parent c671103289
commit abcb39b638
9 changed files with 20 additions and 16 deletions

View File

@ -110,8 +110,9 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
expectedChallengeResponseString = WebSocketUtil.base64(sha1); expectedChallengeResponseString = WebSocketUtil.base64(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("WS Version 07 Client Handshake key: %s. Expected response: %s.", key, logger.debug(
expectedChallengeResponseString)); "WebSocket version 07 client handshake key: {}, expected response: {}",
key, expectedChallengeResponseString);
} }
// Format request // Format request

View File

@ -110,8 +110,9 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
expectedChallengeResponseString = WebSocketUtil.base64(sha1); expectedChallengeResponseString = WebSocketUtil.base64(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("WS Version 08 Client Handshake key: %s. Expected response: %s.", key, logger.debug(
expectedChallengeResponseString)); "WebSocket version 08 client handshake key: {}, expected response: {}",
key, expectedChallengeResponseString);
} }
// Format request // Format request

View File

@ -110,8 +110,9 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
expectedChallengeResponseString = WebSocketUtil.base64(sha1); expectedChallengeResponseString = WebSocketUtil.base64(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("WS Version 13 Client Handshake key: %s. Expected response: %s.", key, logger.debug(
expectedChallengeResponseString)); "WebSocket version 13 client handshake key: {}, expected response: {}",
key, expectedChallengeResponseString);
} }
// Format request // Format request

View File

@ -156,7 +156,7 @@ public abstract class WebSocketServerHandshaker {
HttpHeaders responseHeaders, final ChannelPromise promise) { HttpHeaders responseHeaders, final ChannelPromise promise) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("%s WS Version %s server handshake", channel, version())); logger.debug("%s WebSocket version %s server handshake", channel, version());
} }
FullHttpResponse response = newHandshakeResponse(req, responseHeaders); FullHttpResponse response = newHandshakeResponse(req, responseHeaders);
ChannelPipeline p = channel.pipeline(); ChannelPipeline p = channel.pipeline();

View File

@ -137,7 +137,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
String selectedSubprotocol = selectSubprotocol(subprotocols); String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) { if (selectedSubprotocol == null) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("Requested subprotocol(s) not supported: %s.", subprotocols)); logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
} }
} else { } else {
res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);

View File

@ -111,7 +111,7 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
String accept = WebSocketUtil.base64(sha1); String accept = WebSocketUtil.base64(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("WS Version 7 Server Handshake key: %s. Response: %s.", key, accept)); logger.debug("WebSocket version 07 server handshake key: {}, response: %s.", key, accept);
} }
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase()); res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
@ -122,7 +122,7 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
String selectedSubprotocol = selectSubprotocol(subprotocols); String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) { if (selectedSubprotocol == null) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("Requested subprotocol(s) not supported: %s.", subprotocols)); logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
} }
} else { } else {
res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);

View File

@ -110,7 +110,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
String accept = WebSocketUtil.base64(sha1); String accept = WebSocketUtil.base64(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("WS Version 8 Server Handshake key: %s. Response: %s.", key, accept)); logger.debug("WebSocket version 08 server handshake key: {}, response: {}", key, accept);
} }
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase()); res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
@ -121,7 +121,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
String selectedSubprotocol = selectSubprotocol(subprotocols); String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) { if (selectedSubprotocol == null) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("Requested subprotocol(s) not supported: %s.", subprotocols)); logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
} }
} else { } else {
res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);

View File

@ -108,7 +108,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
String accept = WebSocketUtil.base64(sha1); String accept = WebSocketUtil.base64(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("WS Version 13 Server Handshake key: %s. Response: %s.", key, accept)); logger.debug("WebSocket version 13 server handshake key: {}, response: {}", key, accept);
} }
res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase()); res.headers().add(Names.UPGRADE, WEBSOCKET.toLowerCase());
@ -119,7 +119,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
String selectedSubprotocol = selectSubprotocol(subprotocols); String selectedSubprotocol = selectSubprotocol(subprotocols);
if (selectedSubprotocol == null) { if (selectedSubprotocol == null) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("Requested subprotocol(s) not supported: %s.", subprotocols)); logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
} }
} else { } else {
res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol); res.headers().add(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);

View File

@ -21,6 +21,7 @@ import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogLevel; import io.netty.util.internal.logging.InternalLogLevel;
@ -38,7 +39,7 @@ public class LoggingHandler extends ChannelDuplexHandler {
private static final LogLevel DEFAULT_LEVEL = LogLevel.DEBUG; private static final LogLevel DEFAULT_LEVEL = LogLevel.DEBUG;
private static final String NEWLINE = String.format("%n"); private static final String NEWLINE = StringUtil.NEWLINE;
private static final String[] BYTE2HEX = new String[256]; private static final String[] BYTE2HEX = new String[256];
private static final String[] HEXPADDING = new String[16]; private static final String[] HEXPADDING = new String[16];
@ -335,7 +336,7 @@ public class LoggingHandler extends ChannelDuplexHandler {
/** /**
* Formats an event and returns the formatted message. This method is currently only used for formatting * Formats an event and returns the formatted message. This method is currently only used for formatting
* {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}. * {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}.
* *
* @param eventName the name of the event * @param eventName the name of the event
* @param firstArg the first argument of the event * @param firstArg the first argument of the event