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