aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/MainEventHandler.java7
-rw-r--r--src/main/java/org/traccar/config/Keys.java45
-rw-r--r--src/main/java/org/traccar/helper/Log.java19
3 files changed, 58 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/MainEventHandler.java b/src/main/java/org/traccar/MainEventHandler.java
index 285f6f57c..df17dce0b 100644
--- a/src/main/java/org/traccar/MainEventHandler.java
+++ b/src/main/java/org/traccar/MainEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.timeout.IdleStateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.traccar.config.Keys;
import org.traccar.database.StatisticsManager;
import org.traccar.helper.DateUtil;
import org.traccar.model.Position;
@@ -37,8 +38,6 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(MainEventHandler.class);
- private static final String DEFAULT_LOGGER_ATTRIBUTES = "time,position,speed,course,accuracy,result";
-
private final Set<String> connectionlessProtocols = new HashSet<>();
private final Set<String> logAttributes = new LinkedHashSet<>();
@@ -48,7 +47,7 @@ public class MainEventHandler extends ChannelInboundHandlerAdapter {
connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split("[, ]")));
}
logAttributes.addAll(Arrays.asList(
- Context.getConfig().getString("logger.attributes", DEFAULT_LOGGER_ATTRIBUTES).split("[, ]")));
+ Context.getConfig().getString(Keys.LOGGER_ATTRIBUTES).split("[, ]")));
}
@Override
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index ea0cf4961..ebe496c4f 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -977,6 +977,51 @@ public final class Keys {
"web.sameSiteCookie",
Collections.singletonList(KeyType.GLOBAL));
+ /**
+ * Output logging to the standard terminal output instead of a log file.
+ */
+ public static final ConfigKey<Boolean> LOGGER_CONSOLE = new ConfigKey<>(
+ "logger.console",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Log file name. For rotating logs, a date is added at the end of the file name for non-current logs.
+ */
+ public static final ConfigKey<String> LOGGER_FILE = new ConfigKey<>(
+ "logger.file",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Logging level. Default value is 'info'.
+ * Available options: off, severe, warning, info, config, fine, finer, finest, all.
+ */
+ public static final ConfigKey<String> LOGGER_LEVEL = new ConfigKey<>(
+ "logger.level",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Print full exception traces. Useful for debugging. By default shortened traces are logged.
+ */
+ public static final ConfigKey<Boolean> LOGGER_FULL_STACK_TRACES = new ConfigKey<>(
+ "logger.fullStackTraces",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Create a new log file daily. Helps with log management. For example, downloading and cleaning logs. Enabled by
+ * default.
+ */
+ public static final ConfigKey<Boolean> LOGGER_ROTATE = new ConfigKey<>(
+ "logger.rotate",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * A list of position attributes to log.
+ */
+ public static final ConfigKey<String> LOGGER_ATTRIBUTES = new ConfigKey<>(
+ "logger.attributes",
+ Collections.singletonList(KeyType.GLOBAL),
+ "time,position,speed,course,accuracy,result");
+
private Keys() {
}
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index 358f11a31..8c67f9ddc 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.traccar.helper;
import org.traccar.config.Config;
+import org.traccar.config.Keys;
import java.io.BufferedWriter;
import java.io.File;
@@ -46,10 +47,10 @@ public final class Log {
private static class RollingFileHandler extends Handler {
- private String name;
+ private final String name;
private String suffix;
private Writer writer;
- private boolean rotate;
+ private final boolean rotate;
RollingFileHandler(String name, boolean rotate) {
this.name = name;
@@ -110,7 +111,7 @@ public final class Log {
public static class LogFormatter extends Formatter {
- private boolean fullStackTraces;
+ private final boolean fullStackTraces;
LogFormatter(boolean fullStackTraces) {
this.fullStackTraces = fullStackTraces;
@@ -178,11 +179,11 @@ public final class Log {
public static void setupLogger(Config config) {
setupLogger(
- config.getBoolean("logger.console"),
- config.getString("logger.file"),
- config.getString("logger.level"),
- config.getBoolean("logger.fullStackTraces"),
- config.getBoolean("logger.rotate"));
+ config.getBoolean(Keys.LOGGER_CONSOLE),
+ config.getString(Keys.LOGGER_FILE),
+ config.getString(Keys.LOGGER_LEVEL),
+ config.getBoolean(Keys.LOGGER_FULL_STACK_TRACES),
+ config.getBoolean(Keys.LOGGER_ROTATE));
}
private static void setupLogger(