aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorGavriel Fleischer <flocsy@gmail.com>2019-01-08 19:44:55 +0200
committerGavriel Fleischer <flocsy@gmail.com>2019-01-08 19:44:55 +0200
commit4270b46343d828081436f9a467230d91aa05e4ec (patch)
treed0723e46b0e9989c5787556da4821bad29471bb8 /src/org
parentb2d79ed768eccad9678a5f05aa10b263ee693e35 (diff)
downloadtrackermap-server-4270b46343d828081436f9a467230d91aa05e4ec.tar.gz
trackermap-server-4270b46343d828081436f9a467230d91aa05e4ec.tar.bz2
trackermap-server-4270b46343d828081436f9a467230d91aa05e4ec.zip
made it possible to customize log order and use any attribute
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/MainEventHandler.java70
1 files changed, 38 insertions, 32 deletions
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());