aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 0d515001d..ee66774ec 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));