diff options
author | Anton Tananaev <anton@traccar.org> | 2024-03-31 08:13:18 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-03-31 08:13:18 -0700 |
commit | 301a643d62ccce053a1eaf10e5516a3d5bcc815f (patch) | |
tree | a904618d76ab7e6712ebf1289bee52f0340cd577 /src/main/java/org/traccar/handler | |
parent | 0b403da4f4fe83517110a09acb1d280396379dfb (diff) | |
download | trackermap-server-301a643d62ccce053a1eaf10e5516a3d5bcc815f.tar.gz trackermap-server-301a643d62ccce053a1eaf10e5516a3d5bcc815f.tar.bz2 trackermap-server-301a643d62ccce053a1eaf10e5516a3d5bcc815f.zip |
Extract position logger
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r-- | src/main/java/org/traccar/handler/network/MainEventHandler.java | 69 |
1 files changed, 2 insertions, 67 deletions
diff --git a/src/main/java/org/traccar/handler/network/MainEventHandler.java b/src/main/java/org/traccar/handler/network/MainEventHandler.java index d6407f1e5..f60004126 100644 --- a/src/main/java/org/traccar/handler/network/MainEventHandler.java +++ b/src/main/java/org/traccar/handler/network/MainEventHandler.java @@ -30,16 +30,11 @@ import org.traccar.BasePipelineFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.config.Config; import org.traccar.config.Keys; -import org.traccar.helper.DateUtil; import org.traccar.helper.NetworkUtil; -import org.traccar.model.Device; -import org.traccar.model.Position; import org.traccar.session.ConnectionManager; -import org.traccar.session.cache.CacheManager; import java.util.Arrays; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.Set; @Singleton @@ -48,76 +43,16 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(MainEventHandler.class); - private final Set<String> connectionlessProtocols = new HashSet<>(); - private final Set<String> logAttributes = new LinkedHashSet<>(); - - private final CacheManager cacheManager; private final ConnectionManager connectionManager; + private final Set<String> connectionlessProtocols = new HashSet<>(); @Inject - public MainEventHandler( - Config config, CacheManager cacheManager, ConnectionManager connectionManager) { - this.cacheManager = cacheManager; + public MainEventHandler(Config config, ConnectionManager connectionManager) { this.connectionManager = connectionManager; String connectionlessProtocolList = config.getString(Keys.STATUS_IGNORE_OFFLINE); if (connectionlessProtocolList != null) { connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split("[, ]"))); } - logAttributes.addAll(Arrays.asList(config.getString(Keys.LOGGER_ATTRIBUTES).split("[, ]"))); - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) { - if (msg instanceof Position) { - - Position position = (Position) msg; - Device device = cacheManager.getObject(Device.class, position.getDeviceId()); - - StringBuilder builder = new StringBuilder(); - builder.append("[").append(NetworkUtil.session(ctx.channel())).append("] "); - builder.append("id: ").append(device.getUniqueId()); - for (String attribute : logAttributes) { - switch (attribute) { - case "time": - builder.append(", time: ").append(DateUtil.formatDate(position.getFixTime(), false)); - break; - case "position": - builder.append(", lat: ").append(String.format("%.5f", position.getLatitude())); - builder.append(", lon: ").append(String.format("%.5f", position.getLongitude())); - break; - case "speed": - if (position.getSpeed() > 0) { - builder.append(", speed: ").append(String.format("%.1f", position.getSpeed())); - } - break; - case "course": - builder.append(", course: ").append(String.format("%.1f", position.getCourse())); - break; - case "accuracy": - if (position.getAccuracy() > 0) { - builder.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy())); - } - break; - case "outdated": - if (position.getOutdated()) { - builder.append(", outdated"); - } - break; - case "invalid": - if (!position.getValid()) { - builder.append(", invalid"); - } - break; - default: - Object value = position.getAttributes().get(attribute); - if (value != null) { - builder.append(", ").append(attribute).append(": ").append(value); - } - break; - } - } - LOGGER.info(builder.toString()); - } } @Override |