aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2023-01-26 09:39:49 -0800
committerGitHub <noreply@github.com>2023-01-26 09:39:49 -0800
commit7d1a4120ebe5304217d617e248125e9663bbbf50 (patch)
tree77be3092219bc3b3f42ace83bdbc3454bceea4d2 /src
parentd0874767e27a021ee898201f8f5e27192e0da64b (diff)
parent2c4a87d08fd84be44f85ab58ae852b8128a48f8f (diff)
downloadtrackermap-server-7d1a4120ebe5304217d617e248125e9663bbbf50.tar.gz
trackermap-server-7d1a4120ebe5304217d617e248125e9663bbbf50.tar.bz2
trackermap-server-7d1a4120ebe5304217d617e248125e9663bbbf50.zip
Merge pull request #5021 from Snowbridge/master
New config parameter logger.rotate.interval
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/config/Keys.java10
-rw-r--r--src/main/java/org/traccar/helper/Log.java18
2 files changed, 21 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 26e922c12..093f4298c 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -1575,6 +1575,16 @@ public final class Keys {
List.of(KeyType.CONFIG));
/**
+ * Log file rotation interval, the default rotation interval is once a day.
+ * This option is ignored if 'logger.rotate' = false
+ * Available options: day, hour
+ */
+ public static final ConfigKey<String> LOGGER_ROTATE_INTERVAL = new StringConfigKey(
+ "logger.rotate.interval",
+ List.of(KeyType.CONFIG),
+ "day");
+
+ /**
* A list of position attributes to log.
*/
public static final ConfigKey<String> LOGGER_ATTRIBUTES = new StringConfigKey(
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index e1b201f9f..9aaf1cfd3 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -55,10 +55,12 @@ public final class Log {
private String suffix;
private Writer writer;
private final boolean rotate;
+ private final String template;
- RollingFileHandler(String name, boolean rotate) {
+ RollingFileHandler(String name, boolean rotate, String rotateInterval) {
this.name = name;
this.rotate = rotate;
+ this.template = rotateInterval.equalsIgnoreCase("HOUR") ? "yyyyMMddHH" : "yyyyMMdd";
}
@Override
@@ -67,7 +69,7 @@ public final class Log {
try {
String suffix = "";
if (rotate) {
- suffix = new SimpleDateFormat("yyyyMMdd").format(new Date(record.getMillis()));
+ suffix = new SimpleDateFormat(template).format(new Date(record.getMillis()));
if (writer != null && !suffix.equals(this.suffix)) {
writer.close();
writer = null;
@@ -169,7 +171,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 +180,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 +189,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 +206,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));