aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorEvgeny S Maksimov <admin@vragam.net>2018-12-20 19:25:15 +0300
committerEvgeny S Maksimov <admin@vragam.net>2018-12-20 19:25:15 +0300
commit9c073673fce9e95827f66ade0dbaa7510b372a0f (patch)
treee7f9bf414f2a9d0a0573d89521dac4e8cad51649 /src/org/traccar/helper
parentd0798cd3699c7ce5cc25daf65335d0670256eda0 (diff)
downloadtrackermap-server-9c073673fce9e95827f66ade0dbaa7510b372a0f.tar.gz
trackermap-server-9c073673fce9e95827f66ade0dbaa7510b372a0f.tar.bz2
trackermap-server-9c073673fce9e95827f66ade0dbaa7510b372a0f.zip
Added logger.rotate configuration parameter
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/Log.java29
1 files changed, 18 insertions, 11 deletions
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));