From c850469c29465abb7ed446492d0bd2351b760203 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 12 Apr 2019 21:13:14 -0700 Subject: Log protocol name instead of port --- src/main/java/org/traccar/BasePipelineFactory.java | 4 +++- src/main/java/org/traccar/handler/StandardLoggingHandler.java | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/BasePipelineFactory.java b/src/main/java/org/traccar/BasePipelineFactory.java index b3d37f689..ac008cdd1 100644 --- a/src/main/java/org/traccar/BasePipelineFactory.java +++ b/src/main/java/org/traccar/BasePipelineFactory.java @@ -56,11 +56,13 @@ public abstract class BasePipelineFactory extends ChannelInitializer { private static final Logger LOGGER = LoggerFactory.getLogger(BasePipelineFactory.class); private final TrackerServer server; + private final String protocol; private boolean eventsEnabled; private int timeout; public BasePipelineFactory(TrackerServer server, String protocol) { this.server = server; + this.protocol = protocol; eventsEnabled = Context.getConfig().getBoolean(Keys.EVENT_ENABLE); timeout = Context.getConfig().getInteger(Keys.PROTOCOL_TIMEOUT.withPrefix(protocol)); if (timeout == 0) { @@ -103,7 +105,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer { } pipeline.addLast(new OpenChannelHandler(server)); pipeline.addLast(new NetworkMessageHandler()); - pipeline.addLast(new StandardLoggingHandler()); + pipeline.addLast(new StandardLoggingHandler(protocol)); addProtocolHandlers(handler -> { if (!(handler instanceof BaseProtocolDecoder || handler instanceof BaseProtocolEncoder)) { diff --git a/src/main/java/org/traccar/handler/StandardLoggingHandler.java b/src/main/java/org/traccar/handler/StandardLoggingHandler.java index 88010458f..13c5f8281 100644 --- a/src/main/java/org/traccar/handler/StandardLoggingHandler.java +++ b/src/main/java/org/traccar/handler/StandardLoggingHandler.java @@ -31,6 +31,12 @@ public class StandardLoggingHandler extends ChannelDuplexHandler { private static final Logger LOGGER = LoggerFactory.getLogger(StandardLoggingHandler.class); + private final String protocol; + + public StandardLoggingHandler(String protocol) { + this.protocol = protocol; + } + @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { log(ctx, false, msg); @@ -58,7 +64,7 @@ public class StandardLoggingHandler extends ChannelDuplexHandler { StringBuilder message = new StringBuilder(); message.append("[").append(ctx.channel().id().asShortText()).append(": "); - message.append(((InetSocketAddress) ctx.channel().localAddress()).getPort()); + message.append(protocol); if (downstream) { message.append(" > "); } else { -- cgit v1.2.3