diff --git a/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_01_server.java b/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_01_server.java index 49569adae7cf4ae0bd509b417f10a023ceff4929..ba9d58667e4765079c1194e8fd5e8ecad284cfe0 100644 --- a/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_01_server.java +++ b/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_01_server.java @@ -34,7 +34,7 @@ public class TestEventLoop_01_server { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; - log.info(buf.toString(Charset.defaultCharset())); + log.info("我是handler1,{}", buf.toString(Charset.defaultCharset())); ctx.fireChannelRead(msg); } }).addLast(group, "handler2", new ChannelInboundHandlerAdapter() { @@ -42,7 +42,7 @@ public class TestEventLoop_01_server { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; - log.info(buf.toString(Charset.defaultCharset())); + log.info("我是handler1,{}", buf.toString(Charset.defaultCharset())); } }); } diff --git a/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_05_ChannelFuture.java b/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_05_ChannelFuture.java index dcfaa00bec2c63bddf313183b4fb99526b873ed2..d7dd1ebe28534534f083d5ac4d85ada9f165e17b 100644 --- a/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_05_ChannelFuture.java +++ b/src/main/java/com/kwan/shuyu/heima/netty_04_netty/c3_channel/TestEventLoop_05_ChannelFuture.java @@ -7,13 +7,15 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.string.StringEncoder; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; import lombok.extern.slf4j.Slf4j; import java.net.InetSocketAddress; import java.util.Scanner; /** - * ChannelFuture + * ChannelFuture和LoggingHandler使用 * * @author : qinyingjie * @version : 2.2.0 @@ -28,10 +30,11 @@ public class TestEventLoop_05_ChannelFuture { .group(new NioEventLoopGroup()) //3.选择客户端channel实现 .channel(NioSocketChannel.class) - // 4.添加处理器 + // 4.添加处理器4 .handler(new ChannelInitializer() { @Override //在连接建立后被调用 protected void initChannel(NioSocketChannel ch) throws Exception { + ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(new StringEncoder()); } })