aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-10-24 08:50:43 +0400
committerAnton Tananaev <anton.tananaev@gmail.com>2018-10-24 08:50:43 +0400
commit49d57451db0b9860f40b2ba53bc96069bb86261f (patch)
tree48d7548f5065740437e9c338af62e665d6717ed2 /src/org
parent39e0ee849d74a04b41e2d22665d03b63fb6b0889 (diff)
downloadtraccar-server-49d57451db0b9860f40b2ba53bc96069bb86261f.tar.gz
traccar-server-49d57451db0b9860f40b2ba53bc96069bb86261f.tar.bz2
traccar-server-49d57451db0b9860f40b2ba53bc96069bb86261f.zip
Default logging on config errors
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/Context.java9
-rw-r--r--src/org/traccar/helper/Log.java25
2 files changed, 28 insertions, 6 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 51c67bd0a..5b22120d7 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -359,8 +359,13 @@ public final class Context {
public static void init(String configFile) throws Exception {
- config = new Config();
- config.load(configFile);
+ try {
+ config = new Config();
+ config.load(configFile);
+ } catch (Exception e) {
+ Log.setupDefaultLogger();
+ throw e;
+ }
if (config.getBoolean("logger.enable")) {
Log.setupLogger(config);
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index 4db2ec6f0..a26da6b30 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -151,7 +151,24 @@ public final class Log {
}
+ public static void setupDefaultLogger() {
+ File jarPath = new File(ClassLoader.getSystemClassLoader().getResource(".").getPath());
+ File logsPath = new File(jarPath, "logs");
+ if (!logsPath.exists() || !logsPath.isDirectory()) {
+ logsPath = jarPath;
+ }
+ setupLogger(false, new File(logsPath, "tracker-server.log").getPath(), Level.WARNING.getName(), false);
+ }
+
public static void setupLogger(Config config) {
+ setupLogger(
+ config.getBoolean("logger.console"),
+ config.getString("logger.file"),
+ config.getString("logger.level"),
+ config.getBoolean("logger.fullStackTraces"));
+ }
+
+ private static void setupLogger(boolean console, String file, String levelString, boolean fullStackTraces) {
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
@@ -159,15 +176,15 @@ public final class Log {
}
Handler handler;
- if (config.getBoolean("logger.console")) {
+ if (console) {
handler = new ConsoleHandler();
} else {
- handler = new RollingFileHandler(config.getString("logger.file"));
+ handler = new RollingFileHandler(file);
}
- handler.setFormatter(new LogFormatter(config.getBoolean("logger.fullStackTraces")));
+ handler.setFormatter(new LogFormatter(fullStackTraces));
- Level level = Level.parse(config.getString("logger.level").toUpperCase());
+ Level level = Level.parse(levelString.toUpperCase());
rootLogger.setLevel(level);
handler.setLevel(level);
handler.setFilter(record -> record != null && !record.getLoggerName().startsWith("sun"));