aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/helper/Log.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/helper/Log.java')
-rw-r--r--src/main/java/org/traccar/helper/Log.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index e1b201f9f..a8bf66827 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -56,18 +56,22 @@ public final class Log {
private Writer writer;
private final boolean rotate;
- RollingFileHandler(String name, boolean rotate) {
+ private final String logFileSuffix;
+
+ RollingFileHandler(String name, boolean rotate, String rotateInterval) {
this.name = name;
this.rotate = rotate;
+ this.logFileSuffix = rotateInterval.equalsIgnoreCase("HOUR") ? "yyyyMMddHH" : "yyyyMMdd";
}
+
@Override
public synchronized void publish(LogRecord record) {
if (isLoggable(record)) {
try {
String suffix = "";
if (rotate) {
- suffix = new SimpleDateFormat("yyyyMMdd").format(new Date(record.getMillis()));
+ suffix = new SimpleDateFormat(this.logFileSuffix).format(new Date(record.getMillis()));
if (writer != null && !suffix.equals(this.suffix)) {
writer.close();
writer = null;
@@ -169,7 +173,7 @@ public final class Log {
public static void setupDefaultLogger() {
String path = null;
- URL url = ClassLoader.getSystemClassLoader().getResource(".");
+ URL url = ClassLoader.getSystemClassLoader().getResource(".");
if (url != null) {
File jarPath = new File(url.getPath());
File logsPath = new File(jarPath, "logs");
@@ -178,7 +182,7 @@ public final class Log {
}
path = new File(logsPath, "tracker-server.log").getPath();
}
- setupLogger(path == null, path, Level.WARNING.getName(), false, true);
+ setupLogger(path == null, path, Level.WARNING.getName(), false, true, "DAY");
}
public static void setupLogger(Config config) {
@@ -187,11 +191,13 @@ public final class Log {
config.getString(Keys.LOGGER_FILE),
config.getString(Keys.LOGGER_LEVEL),
config.getBoolean(Keys.LOGGER_FULL_STACK_TRACES),
- config.getBoolean(Keys.LOGGER_ROTATE));
+ config.getBoolean(Keys.LOGGER_ROTATE),
+ config.getString(Keys.LOGGER_ROTATE_INTERVAL));
}
private static void setupLogger(
- boolean console, String file, String levelString, boolean fullStackTraces, boolean rotate) {
+ boolean console, String file, String levelString,
+ boolean fullStackTraces, boolean rotate, String rotateInterval) {
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
@@ -202,7 +208,7 @@ public final class Log {
if (console) {
handler = new ConsoleHandler();
} else {
- handler = new RollingFileHandler(file, rotate);
+ handler = new RollingFileHandler(file, rotate, rotateInterval);
}
handler.setFormatter(new LogFormatter(fullStackTraces));