Using public LogLevel for HTTP/2 frame logging.

Motivation:

The Http2FrameLogger is currently using the internal logging classes. We should change this so that it's using the public classes and then converts internally.

Modifications:

Modified Http2FrameLogger and the examples to use the public LogLevel class.

Result:

Fixes #2512
This commit is contained in:
nmittler 2015-03-17 07:52:02 -07:00
parent 9ec4c39186
commit c14e6597ae
4 changed files with 23 additions and 13 deletions

View File

@ -16,9 +16,11 @@
package io.netty.handler.codec.http2; package io.netty.handler.codec.http2;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.handler.logging.LogLevel;
import io.netty.util.internal.logging.InternalLogLevel; import io.netty.util.internal.logging.InternalLogLevel;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -37,11 +39,19 @@ public class Http2FrameLogger extends ChannelHandlerAdapter {
private final InternalLogger logger; private final InternalLogger logger;
private final InternalLogLevel level; private final InternalLogLevel level;
public Http2FrameLogger(InternalLogLevel level) { public Http2FrameLogger(LogLevel level) {
this(level, InternalLoggerFactory.getInstance(Http2FrameLogger.class)); this(level.toInternalLevel(), InternalLoggerFactory.getInstance(Http2FrameLogger.class));
} }
public Http2FrameLogger(InternalLogLevel level, InternalLogger logger) { public Http2FrameLogger(LogLevel level, String name) {
this(level.toInternalLevel(), InternalLoggerFactory.getInstance(name));
}
public Http2FrameLogger(LogLevel level, Class<?> clazz) {
this(level.toInternalLevel(), InternalLoggerFactory.getInstance(clazz));
}
private Http2FrameLogger(InternalLogLevel level, InternalLogger logger) {
this.level = checkNotNull(level, "level"); this.level = checkNotNull(level, "level");
this.logger = checkNotNull(logger, "logger"); this.logger = checkNotNull(logger, "logger");
} }

View File

@ -14,7 +14,8 @@
*/ */
package io.netty.example.http2.client; package io.netty.example.http2.client;
import static io.netty.util.internal.logging.InternalLogLevel.INFO; import static io.netty.handler.logging.LogLevel.INFO;
import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@ -39,14 +40,12 @@ import io.netty.handler.codec.http2.Http2OutboundFrameLogger;
import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler; import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler;
import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapter; import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapter;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import io.netty.util.internal.logging.InternalLoggerFactory;
/** /**
* Configures the client pipeline to support HTTP/2 frames. * Configures the client pipeline to support HTTP/2 frames.
*/ */
public class Http2ClientInitializer extends ChannelInitializer<SocketChannel> { public class Http2ClientInitializer extends ChannelInitializer<SocketChannel> {
private static final Http2FrameLogger logger = private static final Http2FrameLogger logger = new Http2FrameLogger(INFO, Http2ClientInitializer.class);
new Http2FrameLogger(INFO, InternalLoggerFactory.getInstance(Http2ClientInitializer.class));
private final SslContext sslCtx; private final SslContext sslCtx;
private final int maxContentLength; private final int maxContentLength;

View File

@ -19,7 +19,8 @@ import static io.netty.buffer.Unpooled.copiedBuffer;
import static io.netty.buffer.Unpooled.unreleasableBuffer; import static io.netty.buffer.Unpooled.unreleasableBuffer;
import static io.netty.example.http2.Http2ExampleUtil.UPGRADE_RESPONSE_HEADER; import static io.netty.example.http2.Http2ExampleUtil.UPGRADE_RESPONSE_HEADER;
import static io.netty.handler.codec.http.HttpResponseStatus.OK; import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.util.internal.logging.InternalLogLevel.INFO; import static io.netty.handler.logging.LogLevel.INFO;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.AsciiString; import io.netty.handler.codec.AsciiString;
@ -40,15 +41,13 @@ import io.netty.handler.codec.http2.Http2Headers;
import io.netty.handler.codec.http2.Http2InboundFrameLogger; import io.netty.handler.codec.http2.Http2InboundFrameLogger;
import io.netty.handler.codec.http2.Http2OutboundFrameLogger; import io.netty.handler.codec.http2.Http2OutboundFrameLogger;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.internal.logging.InternalLoggerFactory;
/** /**
* A simple handler that responds with the message "Hello World!". * A simple handler that responds with the message "Hello World!".
*/ */
public class HelloWorldHttp2Handler extends Http2ConnectionHandler { public class HelloWorldHttp2Handler extends Http2ConnectionHandler {
private static final Http2FrameLogger logger = new Http2FrameLogger(INFO, private static final Http2FrameLogger logger = new Http2FrameLogger(INFO, HelloWorldHttp2Handler.class);
InternalLoggerFactory.getInstance(HelloWorldHttp2Handler.class));
static final ByteBuf RESPONSE_BYTES = unreleasableBuffer(copiedBuffer("Hello World", CharsetUtil.UTF_8)); static final ByteBuf RESPONSE_BYTES = unreleasableBuffer(copiedBuffer("Hello World", CharsetUtil.UTF_8));
public HelloWorldHttp2Handler() { public HelloWorldHttp2Handler() {

View File

@ -34,11 +34,13 @@ public enum LogLevel {
} }
/** /**
* Converts the specified {@link LogLevel} to its {@link InternalLogLevel} variant. * For internal use only.
*
* <p/>Converts the specified {@link LogLevel} to its {@link InternalLogLevel} variant.
* *
* @return the converted level. * @return the converted level.
*/ */
InternalLogLevel toInternalLevel() { public InternalLogLevel toInternalLevel() {
return internalLevel; return internalLevel;
} }
} }