aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/MainEventHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-02 08:22:53 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-02 08:22:53 -0700
commit9633eccdead886ed0b580707ad76cdf06df9a603 (patch)
tree22144dad702d22318c62d8adff96851b605b9b48 /src/main/java/org/traccar/MainEventHandler.java
parent19869710f012cbf1a32063021d59aa2d58688e6b (diff)
downloadtrackermap-server-9633eccdead886ed0b580707ad76cdf06df9a603.tar.gz
trackermap-server-9633eccdead886ed0b580707ad76cdf06df9a603.tar.bz2
trackermap-server-9633eccdead886ed0b580707ad76cdf06df9a603.zip
Log transport layer protocol
Diffstat (limited to 'src/main/java/org/traccar/MainEventHandler.java')
-rw-r--r--src/main/java/org/traccar/MainEventHandler.java17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/MainEventHandler.java b/src/main/java/org/traccar/MainEventHandler.java
index a3f6f4105..f1f2527bc 100644
--- a/src/main/java/org/traccar/MainEventHandler.java
+++ b/src/main/java/org/traccar/MainEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import org.traccar.config.Keys;
import org.traccar.database.StatisticsManager;
import org.traccar.helper.DateUtil;
+import org.traccar.helper.NetworkUtil;
import org.traccar.model.Position;
import org.traccar.storage.StorageException;
@@ -64,7 +65,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
String uniqueId = Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId();
StringBuilder builder = new StringBuilder();
- builder.append(formatChannel(ctx.channel())).append(" ");
+ builder.append("[").append(NetworkUtil.session(ctx.channel())).append("] ");
builder.append("id: ").append(uniqueId);
for (String attribute : logAttributes) {
switch (attribute) {
@@ -113,20 +114,16 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
}
}
- private static String formatChannel(Channel channel) {
- return String.format("[%s]", channel.id().asShortText());
- }
-
@Override
public void channelActive(ChannelHandlerContext ctx) {
if (!(ctx.channel() instanceof DatagramChannel)) {
- LOGGER.info(formatChannel(ctx.channel()) + " connected");
+ LOGGER.info("[{}] connected", NetworkUtil.session(ctx.channel()));
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
- LOGGER.info(formatChannel(ctx.channel()) + " disconnected");
+ LOGGER.info("[{}] disconnected", NetworkUtil.session(ctx.channel()));
closeChannel(ctx.channel());
if (BasePipelineFactory.getHandler(ctx.pipeline(), HttpRequestDecoder.class) == null
@@ -140,14 +137,14 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
while (cause.getCause() != null && cause.getCause() != cause) {
cause = cause.getCause();
}
- LOGGER.warn(formatChannel(ctx.channel()) + " error", cause);
+ LOGGER.info("[{}] error", NetworkUtil.session(ctx.channel()), cause);
closeChannel(ctx.channel());
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof IdleStateEvent) {
- LOGGER.info(formatChannel(ctx.channel()) + " timed out");
+ LOGGER.info("[{}] timed out", NetworkUtil.session(ctx.channel()));
closeChannel(ctx.channel());
}
}