Check if loglevel is enabled before logging

This commit is contained in:
norman 2012-02-27 07:37:59 +01:00
parent 3b1b2f0b1d
commit a0f9afb1eb

View File

@ -118,7 +118,9 @@ public class HttpTunnelingServlet extends HttpServlet {
try { try {
destroyChannelFactory(channelFactory); destroyChannelFactory(channelFactory);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Failed to destroy a channel factory.", e); if (logger.isWarnEnabled()) {
logger.warn("Failed to destroy a channel factory.", e);
}
} }
} }
@ -130,7 +132,9 @@ public class HttpTunnelingServlet extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse res) protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { throws ServletException, IOException {
if (!"POST".equalsIgnoreCase(req.getMethod())) { if (!"POST".equalsIgnoreCase(req.getMethod())) {
logger.warn("Unallowed method: " + req.getMethod()); if (logger.isWarnEnabled()) {
logger.warn("Unallowed method: " + req.getMethod());
}
res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return; return;
} }
@ -143,8 +147,10 @@ public class HttpTunnelingServlet extends HttpServlet {
Channel channel = channelFactory.newChannel(pipeline); Channel channel = channelFactory.newChannel(pipeline);
ChannelFuture future = channel.connect(remoteAddress).awaitUninterruptibly(); ChannelFuture future = channel.connect(remoteAddress).awaitUninterruptibly();
if (!future.isSuccess()) { if (!future.isSuccess()) {
Throwable cause = future.getCause(); if (logger.isWarnEnabled()) {
logger.warn("Endpoint unavailable: " + cause.getMessage(), cause); Throwable cause = future.getCause();
logger.warn("Endpoint unavailable: " + cause.getMessage(), cause);
}
res.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); res.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return; return;
} }
@ -233,7 +239,9 @@ public class HttpTunnelingServlet extends HttpServlet {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
logger.warn("Unexpected exception while HTTP tunneling", e.getCause()); if (logger.isWarnEnabled()) {
logger.warn("Unexpected exception while HTTP tunneling", e.getCause());
}
e.getChannel().close(); e.getChannel().close();
} }
} }