aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-15 12:29:47 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-15 12:29:47 +1200
commitc78a8ed5703db32f00a0260939cdd87b011c9bcd (patch)
tree31729a83718eaec318afd2588f339d4ea3e38c41 /src/org
parentfa26dd5f14a991f327c26517a645c6b4f77c4a73 (diff)
downloadtrackermap-server-c78a8ed5703db32f00a0260939cdd87b011c9bcd.tar.gz
trackermap-server-c78a8ed5703db32f00a0260939cdd87b011c9bcd.tar.bz2
trackermap-server-c78a8ed5703db32f00a0260939cdd87b011c9bcd.zip
More service improvements
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/WindowsService.java2
-rw-r--r--src/org/traccar/helper/Log.java22
2 files changed, 21 insertions, 3 deletions
diff --git a/src/org/traccar/WindowsService.java b/src/org/traccar/WindowsService.java
index dccb01559..c1a5a1017 100644
--- a/src/org/traccar/WindowsService.java
+++ b/src/org/traccar/WindowsService.java
@@ -182,6 +182,8 @@ public abstract class WindowsService {
reportStatus(Winsvc.SERVICE_START_PENDING, WinError.NO_ERROR, 3000);
reportStatus(Winsvc.SERVICE_RUNNING, WinError.NO_ERROR, 0);
+ Thread.currentThread().setContextClassLoader(WindowsService.class.getClassLoader());
+
run();
reportStatus(Winsvc.SERVICE_STOPPED, WinError.NO_ERROR, 0);
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index 42cd07cef..d606c7355 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -21,6 +21,8 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -97,6 +99,12 @@ public final class Log {
public static class LogFormatter extends Formatter {
+ private boolean fullStackTraces;
+
+ LogFormatter(boolean fullStackTraces) {
+ this.fullStackTraces = fullStackTraces;
+ }
+
private static String formatLevel(Level level) {
switch (level.getName()) {
case "FINEST":
@@ -119,7 +127,15 @@ public final class Log {
StringBuilder message = new StringBuilder(record.getMessage());
if (record.getThrown() != null) {
- message.append(" - ").append(exceptionStack(record.getThrown()));
+ message.append(" - ");
+ if (fullStackTraces) {
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(stringWriter);
+ record.getThrown().printStackTrace(printWriter);
+ message.append(System.lineSeparator()).append(stringWriter.toString());
+ } else {
+ message.append(exceptionStack(record.getThrown()));
+ }
}
return String.format("%1$tF %1$tT %2$5s: %3$s%n",
@@ -128,7 +144,7 @@ public final class Log {
}
- public static void setupLogger(Config config) throws IOException {
+ public static void setupLogger(Config config) {
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
@@ -142,7 +158,7 @@ public final class Log {
handler = new RollingFileHandler(config.getString("logger.file"));
}
- handler.setFormatter(new LogFormatter());
+ handler.setFormatter(new LogFormatter(config.getBoolean("logger.fullStackTraces")));
handler.setLevel(Level.parse(config.getString("logger.level").toUpperCase()));
rootLogger.addHandler(handler);