mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Update log viewer, add uncalibrated modal (#108)
Adds a prettier log viewer, with the ability to filter logs. Also warns user and prevents switching into 3d mode if the resolution is uncalibrated.
This commit is contained in:
@@ -57,17 +57,17 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
public static void saveUploadedSettingsZip(File uploadPath) {
|
||||
logger.info(uploadPath.getAbsolutePath());
|
||||
var folderPath = Path.of(System.getProperty("java.io.tmpdir"), "photonvision").toFile();
|
||||
folderPath.mkdirs();
|
||||
ZipUtil.unpack(uploadPath, folderPath);
|
||||
FileUtils.deleteDirectory(getRootFolder());
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.copyDirectory(folderPath, getRootFolder().toFile());
|
||||
logger.info("Copied settings successfully!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Exception copying uploaded settings!", e);
|
||||
return;
|
||||
}
|
||||
System.exit(666);
|
||||
}
|
||||
|
||||
public PhotonConfiguration getConfig() {
|
||||
@@ -159,8 +159,6 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
public void saveToDisk() {
|
||||
logger.info("Saving settings...");
|
||||
|
||||
// Delete old configs
|
||||
FileUtils.deleteDirectory(camerasFolder.toPath());
|
||||
|
||||
@@ -214,6 +212,7 @@ public class ConfigManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("Settings saved!");
|
||||
}
|
||||
|
||||
private HashMap<String, CameraConfiguration> loadCameraConfigs() {
|
||||
@@ -341,7 +340,7 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
public void requestSave() {
|
||||
logger.debug("Requesting save...");
|
||||
logger.trace("Requesting save...");
|
||||
saveRequestTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
package org.photonvision.common.logging;
|
||||
|
||||
public enum LogLevel {
|
||||
OFF(0, Logger.ANSI_BLACK),
|
||||
ERROR(1, Logger.ANSI_RED),
|
||||
WARN(2, Logger.ANSI_YELLOW),
|
||||
INFO(3, Logger.ANSI_GREEN),
|
||||
DEBUG(4, Logger.ANSI_WHITE),
|
||||
TRACE(5, Logger.ANSI_CYAN);
|
||||
ERROR(0, Logger.ANSI_RED),
|
||||
WARN(1, Logger.ANSI_YELLOW),
|
||||
INFO(2, Logger.ANSI_GREEN),
|
||||
DEBUG(3, Logger.ANSI_WHITE),
|
||||
TRACE(4, Logger.ANSI_CYAN);
|
||||
|
||||
public final String colorCode;
|
||||
public final int code;
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.photonvision.common.configuration.ConfigManager;
|
||||
import org.photonvision.common.dataflow.DataChangeService;
|
||||
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
|
||||
@@ -47,6 +48,11 @@ public class Logger {
|
||||
private static final SimpleDateFormat simpleDateFormat =
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private static final List<Pair<String, LogLevel>> uiBacklog = new ArrayList<>();
|
||||
private static boolean connected = false;
|
||||
|
||||
private static UILogAppender uiLogAppender = new UILogAppender();
|
||||
|
||||
private final String className;
|
||||
private final LogGroup group;
|
||||
|
||||
@@ -97,7 +103,7 @@ public class Logger {
|
||||
|
||||
static {
|
||||
currentAppenders.add(new ConsoleLogAppender());
|
||||
currentAppenders.add(new UILogAppender());
|
||||
currentAppenders.add(uiLogAppender);
|
||||
addFileAppender(ConfigManager.getInstance().getLogPath());
|
||||
}
|
||||
|
||||
@@ -126,6 +132,15 @@ public class Logger {
|
||||
var formattedMessage = format(message, level, group, clazz, shouldColor);
|
||||
a.log(formattedMessage, level);
|
||||
}
|
||||
if (!connected) uiBacklog.add(Pair.of(format(message, level, group, clazz, false), level));
|
||||
}
|
||||
|
||||
public static void sendConnectedBacklog() {
|
||||
for (var message : uiBacklog) {
|
||||
uiLogAppender.log(message.getLeft(), message.getRight());
|
||||
}
|
||||
connected = true;
|
||||
uiBacklog.clear();
|
||||
}
|
||||
|
||||
public boolean shouldLog(LogLevel logLevel) {
|
||||
@@ -244,6 +259,7 @@ public class Logger {
|
||||
|
||||
private static class FileLogAppender implements LogAppender {
|
||||
private OutputStream out;
|
||||
private boolean wantsFlush;
|
||||
|
||||
public FileLogAppender(Path logFilePath) {
|
||||
try {
|
||||
@@ -253,7 +269,10 @@ public class Logger {
|
||||
"FileLogAppender",
|
||||
() -> {
|
||||
try {
|
||||
out.flush();
|
||||
if (wantsFlush) {
|
||||
out.flush();
|
||||
wantsFlush = false;
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
},
|
||||
@@ -269,6 +288,7 @@ public class Logger {
|
||||
message += "\n";
|
||||
try {
|
||||
out.write(message.getBytes());
|
||||
wantsFlush = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user