Do NOT use InternalLogger in examples

This commit is contained in:
Trustin Lee 2013-02-11 20:17:35 +09:00
parent b4f4b95739
commit 3f16f0b4d2
7 changed files with 38 additions and 38 deletions

View File

@ -34,8 +34,6 @@ import io.netty.handler.codec.http.multipart.HttpDataFactory;
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import java.io.BufferedWriter;
import java.io.File;
@ -44,13 +42,15 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* This class is meant to be run against {@link HttpUploadServer}.
*/
public class HttpUploadClient {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadClient.class);
private static final Logger logger = Logger.getLogger(HttpUploadClient.class.getName());
private final String baseUri;
private final String filePath;
@ -75,7 +75,7 @@ public class HttpUploadClient {
try {
uriSimple = new URI(postSimple);
} catch (URISyntaxException e) {
logger.error("Invalid URI syntax" + e.getCause());
logger.log(Level.WARNING, "Invalid URI syntax", e);
return;
}
String scheme = uriSimple.getScheme() == null ? "http" : uriSimple.getScheme();
@ -90,7 +90,7 @@ public class HttpUploadClient {
}
if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
logger.error("Only HTTP(S) is supported.");
logger.log(Level.WARNING, "Only HTTP(S) is supported.");
return;
}
@ -100,12 +100,12 @@ public class HttpUploadClient {
try {
uriFile = new URI(postFile);
} catch (URISyntaxException e) {
logger.error("Error: " + e.getMessage());
logger.log(Level.WARNING, "Error: ", e);
return;
}
File file = new File(filePath);
if (!file.canRead()) {
logger.error("A correct path is needed");
logger.log(Level.WARNING, "A correct path is needed");
return;
}
@ -172,7 +172,7 @@ public class HttpUploadClient {
try {
uriGet = new URI(encoder.toString());
} catch (URISyntaxException e) {
logger.error("Error: " + e.getMessage());
logger.log(Level.WARNING, "Error: ", e);
return null;
}

View File

@ -22,15 +22,15 @@ import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import java.util.logging.Logger;
/**
* Handler that just dumps the contents of the response from the server
*/
public class HttpUploadClientHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadClientHandler.class);
private static final Logger logger = Logger.getLogger(HttpUploadClientHandler.class.getName());
private boolean readingChunks;

View File

@ -46,8 +46,6 @@ import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.NotEnoughDat
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
import io.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import java.io.IOException;
import java.net.URI;
@ -56,13 +54,15 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import static io.netty.buffer.Unpooled.*;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadServerHandler.class);
private static final Logger logger = Logger.getLogger(HttpUploadServerHandler.class.getName());
private HttpRequest request;
@ -422,7 +422,7 @@ public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error(responseContent.toString(), cause);
logger.log(Level.WARNING, responseContent.toString(), cause);
ctx.channel().close();
}
}

View File

@ -34,8 +34,9 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*;
@ -46,7 +47,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
* Handles handshakes and messages
*/
public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(AutobahnServerHandler.class);
private static final Logger logger = Logger.getLogger(AutobahnServerHandler.class.getName());
private WebSocketServerHandshaker handshaker;
@ -84,9 +85,9 @@ public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<O
}
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), frame.getClass()
.getSimpleName()));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format(
"Channel %s received %s", ctx.channel().id(), frame.getClass().getSimpleName()));
}
if (frame instanceof CloseWebSocketFrame) {

View File

@ -32,8 +32,9 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
@ -45,7 +46,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
* Handles handshakes and messages
*/
public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketServerHandler.class);
private static final Logger logger = Logger.getLogger(WebSocketServerHandler.class.getName());
private static final String WEBSOCKET_PATH = "/websocket";
@ -121,8 +122,8 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
// Send the uppercase string back.
String request = ((TextWebSocketFrame) frame).text();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), request));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
}
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
}

View File

@ -33,8 +33,9 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
@ -46,7 +47,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
* Handles handshakes and messages
*/
public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerHandler.class);
private static final Logger logger = Logger.getLogger(WebSocketSslServerHandler.class.getName());
private static final String WEBSOCKET_PATH = "/websocket";
@ -123,8 +124,8 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
// Send the uppercase string back.
String request = ((TextWebSocketFrame) frame).text();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), request));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
}
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
}

View File

@ -15,21 +15,20 @@
*/
package io.netty.example.http.websocketx.sslserver;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.Security;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Creates a {@link SSLContext} for just server certificates.
*/
public final class WebSocketSslServerSslContext {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerSslContext.class);
private static final Logger logger = Logger.getLogger(WebSocketSslServerSslContext.class.getName());
private static final String PROTOCOL = "TLS";
private final SSLContext _serverContext;
@ -83,9 +82,7 @@ public final class WebSocketSslServerSslContext {
throw new Error("Failed to initialize the server-side SSLContext", e);
}
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Error initializing SslContextManager. " + ex.getMessage(), ex);
}
logger.log(Level.WARNING, "Error initializing SslContextManager.", ex);
System.exit(1);
} finally {
_serverContext = serverContext;