diff options
-rw-r--r-- | src/org/traccar/MainEventHandler.java | 56 | ||||
-rw-r--r-- | src/org/traccar/ServerManager.java | 2 | ||||
-rw-r--r-- | src/org/traccar/geocoder/GoogleGeocoder.java | 5 | ||||
-rw-r--r-- | src/org/traccar/geocoder/JsonGeocoder.java | 9 |
4 files changed, 56 insertions, 16 deletions
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 8ca73dd77..76cb3e132 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -34,14 +34,18 @@ 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<String> connectionlessProtocols = new HashSet<>(); + private final Set<String> logEvents; public MainEventHandler() { String connectionlessProtocolList = Context.getConfig().getString("status.ignoreOffline"); if (connectionlessProtocolList != null) { connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split(","))); } + logEvents = new HashSet<>(Arrays.asList( + Context.getConfig().getString("logger.events", DEFAULT_LOGGER_EVENTS).split(","))); } @Override @@ -61,19 +65,45 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter { 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) { - s.append(", speed: ").append(String.format("%.1f", position.getSpeed())); - } - s.append(", course: ").append(String.format("%.1f", position.getCourse())); - if (position.getAccuracy() > 0) { - s.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy())); - } - 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()); diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index cdc679e8a..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("One of the protocols is disabled due to port conflict"); + LOGGER.warn("Port %d is disabled due to conflict", server.getPort()); } } } diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java index af9b58a90..9494cab45 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 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 80123e01e..ed59a1d8d 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. Error: " + parseError(json); if (callback != null) { - callback.onFailure(new GeocoderException("Empty address")); + 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 parseError(JsonObject json) { + return null; + } + } |