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.java51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index 9aaf1cfd3..d01d70559 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2024 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package org.traccar.helper;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.model.Pair;
import java.io.BufferedWriter;
import java.io.File;
@@ -30,9 +31,9 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileStore;
import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Date;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
@@ -40,6 +41,7 @@ import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
+import java.util.stream.Stream;
public final class Log {
@@ -124,21 +126,13 @@ public final class Log {
}
private static String formatLevel(Level level) {
- switch (level.getName()) {
- case "FINEST":
- return "TRACE";
- case "FINER":
- case "FINE":
- case "CONFIG":
- return "DEBUG";
- case "INFO":
- return "INFO";
- case "WARNING":
- return "WARN";
- case "SEVERE":
- default:
- return "ERROR";
- }
+ return switch (level.getName()) {
+ case "FINEST" -> "TRACE";
+ case "FINER", "FINE", "CONFIG" -> "DEBUG";
+ case "INFO" -> "INFO";
+ case "WARNING" -> "WARN";
+ default -> "ERROR";
+ };
}
@Override
@@ -150,7 +144,7 @@ public final class Log {
}
if (record.getThrown() != null) {
- if (message.length() > 0) {
+ if (!message.isEmpty()) {
message.append(" - ");
}
if (fullStackTraces) {
@@ -278,17 +272,22 @@ public final class Log {
}
public static long[] getStorageSpace() {
- long usable = 0;
- long total = 0;
- for (Path root : FileSystems.getDefault().getRootDirectories()) {
+ var stores = new ArrayList<Pair<Long, Long>>();
+ for (FileStore store : FileSystems.getDefault().getFileStores()) {
try {
- FileStore store = Files.getFileStore(root);
- usable += store.getUsableSpace();
- total += store.getTotalSpace();
+ long usableSpace = store.getUsableSpace();
+ long totalSpace = store.getTotalSpace();
+ if (totalSpace > 1_000_000_000) {
+ stores.add(new Pair<>(usableSpace, totalSpace));
+ }
} catch (IOException ignored) {
}
}
- return new long[]{usable, total};
+ return stores.stream()
+ .sorted(Comparator.comparingDouble(p -> p.first() / (double) p.second()))
+ .flatMap(p -> Stream.of(p.first(), p.second()))
+ .mapToLong(Long::longValue)
+ .toArray();
}
}