aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-01-11 13:26:27 -0800
committerGitHub <noreply@github.com>2019-01-11 13:26:27 -0800
commit9bfa95e5d449c1353015680f2dafeeebab907652 (patch)
tree501c452adf8ac98df9820f581ea79518d97d8374
parent33983258bb660d1cd51f35d5df1f363ebb885bc4 (diff)
parent9c073673fce9e95827f66ade0dbaa7510b372a0f (diff)
downloadtrackermap-server-9bfa95e5d449c1353015680f2dafeeebab907652.tar.gz
trackermap-server-9bfa95e5d449c1353015680f2dafeeebab907652.tar.bz2
trackermap-server-9bfa95e5d449c1353015680f2dafeeebab907652.zip
Merge pull request #4188 from iEvgeny/logrotate
Added logger.rotate configuration parameter for compatibility with logrotate
-rw-r--r--setup/default.xml1
-rw-r--r--src/org/traccar/helper/Log.java29
2 files changed, 19 insertions, 11 deletions
diff --git a/setup/default.xml b/setup/default.xml
index 447380c32..f0aecddb4 100644
--- a/setup/default.xml
+++ b/setup/default.xml
@@ -21,6 +21,7 @@
<entry key='logger.enable'>true</entry>
<entry key='logger.level'>info</entry>
<entry key='logger.file'>./logs/tracker-server.log</entry>
+ <entry key='logger.rotate'>true</entry>
<entry key='filter.enable'>true</entry>
<entry key='filter.future'>86400</entry>
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index 9519a33f1..6f5a875bc 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -48,21 +48,26 @@ public final class Log {
private String name;
private String suffix;
private Writer writer;
+ private boolean rotate;
- RollingFileHandler(String name) {
+ RollingFileHandler(String name, boolean rotate) {
this.name = name;
+ this.rotate = rotate;
}
@Override
public synchronized void publish(LogRecord record) {
if (isLoggable(record)) {
try {
- String suffix = new SimpleDateFormat("yyyyMMdd").format(new Date(record.getMillis()));
- if (writer != null && !suffix.equals(this.suffix)) {
- writer.close();
- writer = null;
- if (!new File(name).renameTo(new File(name + "." + this.suffix))) {
- throw new RuntimeException("Log file renaiming failed");
+ String suffix = "";
+ if (rotate) {
+ suffix = new SimpleDateFormat("yyyyMMdd").format(new Date(record.getMillis()));
+ if (writer != null && !suffix.equals(this.suffix)) {
+ writer.close();
+ writer = null;
+ if (!new File(name).renameTo(new File(name + "." + this.suffix))) {
+ throw new RuntimeException("Log file renaiming failed");
+ }
}
}
if (writer == null) {
@@ -162,7 +167,7 @@ public final class Log {
if (!logsPath.exists() || !logsPath.isDirectory()) {
logsPath = jarPath;
}
- setupLogger(false, new File(logsPath, "tracker-server.log").getPath(), Level.WARNING.getName(), false);
+ setupLogger(false, new File(logsPath, "tracker-server.log").getPath(), Level.WARNING.getName(), false, true);
}
public static void setupLogger(Config config) {
@@ -170,10 +175,12 @@ public final class Log {
config.getBoolean("logger.console"),
config.getString("logger.file"),
config.getString("logger.level"),
- config.getBoolean("logger.fullStackTraces"));
+ config.getBoolean("logger.fullStackTraces"),
+ config.getBoolean("logger.rotate"));
}
- private static void setupLogger(boolean console, String file, String levelString, boolean fullStackTraces) {
+ private static void setupLogger(
+ boolean console, String file, String levelString, boolean fullStackTraces, boolean rotate) {
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
@@ -184,7 +191,7 @@ public final class Log {
if (console) {
handler = new ConsoleHandler();
} else {
- handler = new RollingFileHandler(file);
+ handler = new RollingFileHandler(file, rotate);
}
handler.setFormatter(new LogFormatter(fullStackTraces));