From 3897d9418dcffe0db9b326661c7f8ef6a2da49ec Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Mon, 7 Jan 2019 22:04:01 +0200 Subject: log error in geocoder --- src/org/traccar/geocoder/JsonGeocoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/geocoder/JsonGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java index 80123e01e..9157297bf 100644 --- a/src/org/traccar/geocoder/JsonGeocoder.java +++ b/src/org/traccar/geocoder/JsonGeocoder.java @@ -65,7 +65,7 @@ public abstract class JsonGeocoder implements Geocoder { return formattedAddress; } else { if (callback != null) { - callback.onFailure(new GeocoderException("Empty address")); + callback.onFailure(new GeocoderException("Empty address. " + json.getString("error_message"))); } else { LOGGER.warn("Empty address"); } -- cgit v1.2.3 From 96878a4baa6706e1903cde05e23cd21bc31348f4 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Mon, 7 Jan 2019 22:12:06 +0200 Subject: log port in case of conflict --- src/org/traccar/ServerManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index cdc679e8a..e279b1f03 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -88,7 +88,7 @@ public class ServerManager { try { server.start(); } catch (BindException e) { - LOGGER.warn("One of the protocols is disabled due to port conflict"); + LOGGER.warn("One of the protocols is disabled due to port conflict: " + server.getPort()); } } } -- cgit v1.2.3 From ac9ca0605726344f8a8242198102ccdd9a52635e Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Mon, 7 Jan 2019 22:14:57 +0200 Subject: log battery level, outdated, invalid --- src/org/traccar/MainEventHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 8ca73dd77..3a8e36146 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -71,6 +71,16 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { if (position.getAccuracy() > 0) { s.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy())); } + if (position.getOutdated()) { + s.append(", outdated"); + } + if (!position.getValid()) { + s.append(", invalid"); + } + Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL); + if (batteryLevel != null) { + s.append(", battery: ").append(batteryLevel).append('%'); + } Object cmdResult = position.getAttributes().get(Position.KEY_RESULT); if (cmdResult != null) { s.append(", result: ").append(cmdResult); -- cgit v1.2.3 From c0316e4a968ea73002954118cafdd958f354370f Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Mon, 7 Jan 2019 22:24:53 +0200 Subject: added getInteger that can return null --- src/org/traccar/MainEventHandler.java | 2 +- src/org/traccar/model/ExtendedModel.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 3a8e36146..a3bbb8fd6 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -77,7 +77,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { if (!position.getValid()) { s.append(", invalid"); } - Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL); + Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL, null); if (batteryLevel != null) { s.append(", battery: ").append(batteryLevel).append('%'); } diff --git a/src/org/traccar/model/ExtendedModel.java b/src/org/traccar/model/ExtendedModel.java index 8353d0e66..8271e41cc 100644 --- a/src/org/traccar/model/ExtendedModel.java +++ b/src/org/traccar/model/ExtendedModel.java @@ -108,14 +108,18 @@ public class ExtendedModel extends BaseModel { } } - public int getInteger(String key) { + public Integer getInteger(String key, Integer defaultValue) { if (attributes.containsKey(key)) { return ((Number) attributes.get(key)).intValue(); } else { - return 0; + return defaultValue; } } + public int getInteger(String key) { + return getInteger(key, 0); + } + public long getLong(String key) { if (attributes.containsKey(key)) { return ((Number) attributes.get(key)).longValue(); -- cgit v1.2.3 From 4d7ba34ddc16a01858d9d18e703be241494dea56 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 01:23:35 +0200 Subject: changed log message for port confict --- src/org/traccar/ServerManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index e279b1f03..bfdbed06d 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -88,7 +88,7 @@ public class ServerManager { try { server.start(); } catch (BindException e) { - LOGGER.warn("One of the protocols is disabled due to port conflict: " + server.getPort()); + LOGGER.warn("Port " + server.getPort() + " is disabled due to conflict"); } } } -- cgit v1.2.3 From cca181a4a70ca729c981bb9c62242042698c7476 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 01:26:29 +0200 Subject: log error in GoogleGeocoder --- src/org/traccar/geocoder/GoogleGeocoder.java | 5 +++++ src/org/traccar/geocoder/JsonGeocoder.java | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java index af9b58a90..23a08b6e2 100644 --- a/src/org/traccar/geocoder/GoogleGeocoder.java +++ b/src/org/traccar/geocoder/GoogleGeocoder.java @@ -90,4 +90,9 @@ public class GoogleGeocoder extends JsonGeocoder { return null; } + @Override + protected String getError(JsonObject json) { + return json.getString("error_message"); + } + } diff --git a/src/org/traccar/geocoder/JsonGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java index 9157297bf..3a0175dae 100644 --- a/src/org/traccar/geocoder/JsonGeocoder.java +++ b/src/org/traccar/geocoder/JsonGeocoder.java @@ -64,10 +64,11 @@ public abstract class JsonGeocoder implements Geocoder { } return formattedAddress; } else { + String msg = "Empty address. " + getError(json); if (callback != null) { - callback.onFailure(new GeocoderException("Empty address. " + json.getString("error_message"))); + callback.onFailure(new GeocoderException(msg)); } else { - LOGGER.warn("Empty address"); + LOGGER.warn(msg); } } return null; @@ -113,4 +114,8 @@ public abstract class JsonGeocoder implements Geocoder { public abstract Address parseAddress(JsonObject json); + protected String getError(JsonObject json) { + return ""; + } + } -- cgit v1.2.3 From ed3d450e03d5c33c4dfdab5b5724ff3d1be344b2 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 01:59:33 +0200 Subject: added logger.events configuration --- src/org/traccar/MainEventHandler.java | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index a3bbb8fd6..5e2870d57 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -15,6 +15,7 @@ */ package org.traccar; +import com.google.common.collect.Sets; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -34,14 +35,17 @@ import java.util.Set; public class MainEventHandler extends ChannelInboundHandlerAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(GeocoderHandler.class); + private static final String DEFAULT_LOGGER_EVENTS = "time,position,speed,course,accuracy,result"; private final Set connectionlessProtocols = new HashSet<>(); + private final Set logEvents; public MainEventHandler() { String connectionlessProtocolList = Context.getConfig().getString("status.ignoreOffline"); if (connectionlessProtocolList != null) { connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split(","))); } + logEvents = Sets.newHashSet(Context.getConfig().getString("logger.events", DEFAULT_LOGGER_EVENTS).split(",")); } @Override @@ -56,34 +60,43 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { } String uniqueId = Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId(); - // Log position StringBuilder s = new StringBuilder(); s.append(formatChannel(ctx.channel())).append(" "); s.append("id: ").append(uniqueId); - s.append(", time: ").append(DateUtil.formatDate(position.getFixTime(), false)); - s.append(", lat: ").append(String.format("%.5f", position.getLatitude())); - s.append(", lon: ").append(String.format("%.5f", position.getLongitude())); - if (position.getSpeed() > 0) { + if (logEvents.contains("time")) { + s.append(", time: ").append(DateUtil.formatDate(position.getFixTime(), false)); + } + if (logEvents.contains("position")) { + s.append(", lat: ").append(String.format("%.5f", position.getLatitude())); + s.append(", lon: ").append(String.format("%.5f", position.getLongitude())); + } + if (position.getSpeed() > 0 && logEvents.contains("speed")) { s.append(", speed: ").append(String.format("%.1f", position.getSpeed())); } - s.append(", course: ").append(String.format("%.1f", position.getCourse())); - if (position.getAccuracy() > 0) { + if (logEvents.contains("course")) { + s.append(", course: ").append(String.format("%.1f", position.getCourse())); + } + if (position.getAccuracy() > 0 && logEvents.contains("accuracy")) { s.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy())); } - if (position.getOutdated()) { + if (position.getOutdated() && logEvents.contains("outdated")) { s.append(", outdated"); } - if (!position.getValid()) { + if (!position.getValid() && logEvents.contains("invalid")) { s.append(", invalid"); } - Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL, null); - if (batteryLevel != null) { - s.append(", battery: ").append(batteryLevel).append('%'); + if (logEvents.contains(Position.KEY_BATTERY_LEVEL)) { + Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL, null); + if (batteryLevel != null) { + s.append(", battery: ").append(batteryLevel).append('%'); + } } - Object cmdResult = position.getAttributes().get(Position.KEY_RESULT); - if (cmdResult != null) { - s.append(", result: ").append(cmdResult); + if (logEvents.contains(Position.KEY_RESULT)) { + Object cmdResult = position.getAttributes().get(Position.KEY_RESULT); + if (cmdResult != null) { + s.append(", result: ").append(cmdResult); + } } LOGGER.info(s.toString()); -- cgit v1.2.3 From 48f3c2ef839fae5d7046da61c8ec683d0a3d2dfb Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 10:55:26 +0200 Subject: renamed method to parseError --- src/org/traccar/geocoder/GoogleGeocoder.java | 2 +- src/org/traccar/geocoder/JsonGeocoder.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java index 23a08b6e2..9494cab45 100644 --- a/src/org/traccar/geocoder/GoogleGeocoder.java +++ b/src/org/traccar/geocoder/GoogleGeocoder.java @@ -91,7 +91,7 @@ public class GoogleGeocoder extends JsonGeocoder { } @Override - protected String getError(JsonObject json) { + protected String parseError(JsonObject json) { return json.getString("error_message"); } diff --git a/src/org/traccar/geocoder/JsonGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java index 3a0175dae..ed59a1d8d 100644 --- a/src/org/traccar/geocoder/JsonGeocoder.java +++ b/src/org/traccar/geocoder/JsonGeocoder.java @@ -64,7 +64,7 @@ public abstract class JsonGeocoder implements Geocoder { } return formattedAddress; } else { - String msg = "Empty address. " + getError(json); + String msg = "Empty address. Error: " + parseError(json); if (callback != null) { callback.onFailure(new GeocoderException(msg)); } else { @@ -114,8 +114,8 @@ public abstract class JsonGeocoder implements Geocoder { public abstract Address parseAddress(JsonObject json); - protected String getError(JsonObject json) { - return ""; + protected String parseError(JsonObject json) { + return null; } } -- cgit v1.2.3 From 4f2b8116b74bc1c2a714bc4143e1b460882b2507 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 10:55:50 +0200 Subject: use Java api --- src/org/traccar/MainEventHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 5e2870d57..3a9f5ee41 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -15,7 +15,6 @@ */ package org.traccar; -import com.google.common.collect.Sets; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -45,7 +44,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { if (connectionlessProtocolList != null) { connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split(","))); } - logEvents = Sets.newHashSet(Context.getConfig().getString("logger.events", DEFAULT_LOGGER_EVENTS).split(",")); + logEvents = new HashSet<>(Arrays.asList(Context.getConfig().getString("logger.events", DEFAULT_LOGGER_EVENTS).split(","))); } @Override @@ -60,6 +59,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { } String uniqueId = Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId(); + // Log position StringBuilder s = new StringBuilder(); s.append(formatChannel(ctx.channel())).append(" "); -- cgit v1.2.3 From cc9c8b2793a000d6ad3e844c5654bd6a996d592b Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 10:56:20 +0200 Subject: use String formatting in logging --- src/org/traccar/ServerManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index bfdbed06d..753156b5c 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -88,7 +88,7 @@ public class ServerManager { try { server.start(); } catch (BindException e) { - LOGGER.warn("Port " + server.getPort() + " is disabled due to conflict"); + LOGGER.warn("Port %d is disabled due to conflict", server.getPort()); } } } -- cgit v1.2.3 From b2d79ed768eccad9678a5f05aa10b263ee693e35 Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 11:06:39 +0200 Subject: 120 chars line limit... --- src/org/traccar/MainEventHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 3a9f5ee41..a43227c8f 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -44,7 +44,8 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { if (connectionlessProtocolList != null) { connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split(","))); } - logEvents = new HashSet<>(Arrays.asList(Context.getConfig().getString("logger.events", DEFAULT_LOGGER_EVENTS).split(","))); + logEvents = new HashSet<>(Arrays.asList( + Context.getConfig().getString("logger.events", DEFAULT_LOGGER_EVENTS).split(","))); } @Override -- cgit v1.2.3 From 4270b46343d828081436f9a467230d91aa05e4ec Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 19:44:55 +0200 Subject: made it possible to customize log order and use any attribute --- src/org/traccar/MainEventHandler.java | 70 +++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index a43227c8f..76cb3e132 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -65,38 +65,44 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { StringBuilder s = new StringBuilder(); s.append(formatChannel(ctx.channel())).append(" "); s.append("id: ").append(uniqueId); - if (logEvents.contains("time")) { - s.append(", time: ").append(DateUtil.formatDate(position.getFixTime(), false)); - } - if (logEvents.contains("position")) { - s.append(", lat: ").append(String.format("%.5f", position.getLatitude())); - s.append(", lon: ").append(String.format("%.5f", position.getLongitude())); - } - if (position.getSpeed() > 0 && logEvents.contains("speed")) { - s.append(", speed: ").append(String.format("%.1f", position.getSpeed())); - } - if (logEvents.contains("course")) { - s.append(", course: ").append(String.format("%.1f", position.getCourse())); - } - if (position.getAccuracy() > 0 && logEvents.contains("accuracy")) { - s.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy())); - } - if (position.getOutdated() && logEvents.contains("outdated")) { - s.append(", outdated"); - } - if (!position.getValid() && logEvents.contains("invalid")) { - s.append(", invalid"); - } - if (logEvents.contains(Position.KEY_BATTERY_LEVEL)) { - Object batteryLevel = position.getInteger(Position.KEY_BATTERY_LEVEL, null); - if (batteryLevel != null) { - s.append(", battery: ").append(batteryLevel).append('%'); - } - } - if (logEvents.contains(Position.KEY_RESULT)) { - Object cmdResult = position.getAttributes().get(Position.KEY_RESULT); - if (cmdResult != null) { - s.append(", result: ").append(cmdResult); + for (String event : logEvents) { + switch (event) { + case "time": + s.append(", time: ").append(DateUtil.formatDate(position.getFixTime(), false)); + break; + case "position": + s.append(", lat: ").append(String.format("%.5f", position.getLatitude())); + s.append(", lon: ").append(String.format("%.5f", position.getLongitude())); + break; + case "speed": + if (position.getSpeed() > 0) { + s.append(", speed: ").append(String.format("%.1f", position.getSpeed())); + } + break; + case "course": + s.append(", course: ").append(String.format("%.1f", position.getCourse())); + break; + case "accuracy": + if (position.getAccuracy() > 0) { + s.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy())); + } + break; + case "outdated": + if (position.getOutdated()) { + s.append(", outdated"); + } + break; + case "invalid": + if (!position.getValid()) { + s.append(", invalid"); + } + break; + default: + Object value = position.getAttributes().get(event); + if (value != null) { + s.append(", ").append(event).append(": ").append(value); + } + break; } } LOGGER.info(s.toString()); -- cgit v1.2.3 From 2bf57a222e2c173df13e4816efb62dfe0f371bfa Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Tue, 8 Jan 2019 19:47:52 +0200 Subject: reverted getInteger --- src/org/traccar/model/ExtendedModel.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/org/traccar/model/ExtendedModel.java b/src/org/traccar/model/ExtendedModel.java index 8271e41cc..8353d0e66 100644 --- a/src/org/traccar/model/ExtendedModel.java +++ b/src/org/traccar/model/ExtendedModel.java @@ -108,18 +108,14 @@ public class ExtendedModel extends BaseModel { } } - public Integer getInteger(String key, Integer defaultValue) { + public int getInteger(String key) { if (attributes.containsKey(key)) { return ((Number) attributes.get(key)).intValue(); } else { - return defaultValue; + return 0; } } - public int getInteger(String key) { - return getInteger(key, 0); - } - public long getLong(String key) { if (attributes.containsKey(key)) { return ((Number) attributes.get(key)).longValue(); -- cgit v1.2.3