优化日志输出
parent
b1705c5d5c
commit
8e570571ad
|
@ -67,7 +67,7 @@ public class TCPServerHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
time = System.currentTimeMillis() - time;
|
||||
if (time > 200)
|
||||
log.info("========={},处理耗时{}ms,", request.getMessageName(), time);
|
||||
log.info("====={},处理耗时{}ms,", request.getMessageName(), time);
|
||||
if (response != null)
|
||||
ctx.writeAndFlush(response);
|
||||
}
|
||||
|
@ -77,20 +77,20 @@ public class TCPServerHandler extends ChannelInboundHandlerAdapter {
|
|||
Channel channel = ctx.channel();
|
||||
Session session = sessionManager.newSession(channel);
|
||||
channel.attr(Session.KEY).set(session);
|
||||
log.info(">>>>>终端连接{}", session);
|
||||
log.info("<<<<<终端连接{}", session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
Session session = ctx.channel().attr(Session.KEY).get();
|
||||
session.invalidate();
|
||||
log.info("<<<<<断开连接{}", session);
|
||||
log.info(">>>>>断开连接{}", session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
|
||||
Session session = ctx.channel().attr(Session.KEY).get();
|
||||
log.warn("<<<<<消息处理异常" + session, e);
|
||||
log.warn(">>>>>消息处理异常" + session, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,7 @@ public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter {
|
|||
hex = ByteBufUtil.hexDump(buf);
|
||||
else
|
||||
hex = ByteBufUtil.hexDump(buf.slice(0, 32)) + "..." + ByteBufUtil.hexDump(buf.slice(buf.readableBytes() - 32, 32));
|
||||
log.info(">>>>>原始报文[ip={}],hex={}", ctx.channel().remoteAddress(), hex);
|
||||
log.info("<<<<<[ip={}],payload={}", ctx.channel().remoteAddress(), hex);
|
||||
}
|
||||
Object message = decoder.decode(buf, ctx.channel().attr(Session.KEY).get());
|
||||
if (message != null)
|
||||
|
|
|
@ -36,7 +36,7 @@ public class MessageEncoderWrapper extends ChannelOutboundHandlerAdapter {
|
|||
else
|
||||
buf = encoder.encode(msg);
|
||||
if (log.isInfoEnabled())
|
||||
log.info("<<<<<原始报文[ip={}],hex={}", ctx.channel().remoteAddress(), ByteBufUtil.hexDump(buf));
|
||||
log.info(">>>>>[ip={}],payload={}", ctx.channel().remoteAddress(), ByteBufUtil.hexDump(buf));
|
||||
|
||||
if (buf.isReadable()) {
|
||||
ctx.write(buf, promise);
|
||||
|
|
|
@ -168,14 +168,14 @@ public class Session {
|
|||
private static final ChannelFutureListener ERROR_LOG_LISTENER = future -> {
|
||||
Throwable t = future.cause();
|
||||
if (t != null)
|
||||
log.error("<<<<<<<<<<消息下发失败", t);
|
||||
log.error(">>>>>>>>>>消息下发失败", t);
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送通知类消息,不接收响应
|
||||
*/
|
||||
public void notify(Object message) {
|
||||
log.info("<<<<<<<<<<消息通知{},{}", this, message);
|
||||
log.info(">>>>>>>>>>消息通知{},{}", this, message);
|
||||
channel.writeAndFlush(message).addListener(ERROR_LOG_LISTENER);
|
||||
}
|
||||
|
||||
|
@ -191,17 +191,17 @@ public class Session {
|
|||
String key = requestKey(request, responseClass);
|
||||
SynchronousQueue syncQueue = this.subscribe(key);
|
||||
if (syncQueue == null) {
|
||||
log.info("<<<<<<<<<<请勿重复发送,{}", request);
|
||||
log.info("==========请勿重复发送,{}", request);
|
||||
}
|
||||
|
||||
T result = null;
|
||||
try {
|
||||
log.info("<<<<<<<<<<消息请求{},{}", this, request);
|
||||
log.info(">>>>>>>>>>消息请求{},{}", this, request);
|
||||
ChannelFuture channelFuture = channel.writeAndFlush(request).addListener(ERROR_LOG_LISTENER);
|
||||
if (channelFuture.awaitUninterruptibly().isSuccess())
|
||||
result = (T) syncQueue.poll(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (Throwable e) {
|
||||
log.warn("<<<<<<<<<<等待响应超时" + this, e);
|
||||
log.warn(">>>>>>>>>>等待响应超时" + this, e);
|
||||
} finally {
|
||||
this.unsubscribe(key);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue