From db88a6d69e036c383b91817991e7e4be1fb8bd54 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 23 Feb 2019 10:25:30 -0800 Subject: Handle common crash --- src/org/traccar/helper/Log.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/org/traccar/helper') diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java index df0c9abc1..667f669fe 100644 --- a/src/org/traccar/helper/Log.java +++ b/src/org/traccar/helper/Log.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2019 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. @@ -25,6 +25,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; @@ -162,12 +163,17 @@ 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; + String path = null; + URL url = ClassLoader.getSystemClassLoader().getResource("."); + if (url != null) { + File jarPath = new File(url.getPath()); + File logsPath = new File(jarPath, "logs"); + if (!logsPath.exists() || !logsPath.isDirectory()) { + logsPath = jarPath; + } + path = new File(logsPath, "tracker-server.log").getPath(); } - setupLogger(false, new File(logsPath, "tracker-server.log").getPath(), Level.WARNING.getName(), false, true); + setupLogger(path == null, path, Level.WARNING.getName(), false, true); } public static void setupLogger(Config config) { -- cgit v1.2.3