mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Various logging cleanups (#65)
* Various logging cleanups * Move device info to string, apply spotless
This commit is contained in:
@@ -224,7 +224,7 @@ public class ConfigManager {
|
||||
driverModeFile.toAbsolutePath(), DriverModePipelineSettings.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("Could not deserialize drivermode.json! Loading defaults");
|
||||
logger.trace(Arrays.toString(e.getStackTrace()));
|
||||
logger.debug(Arrays.toString(e.getStackTrace()));
|
||||
driverMode = new DriverModePipelineSettings();
|
||||
}
|
||||
if (driverMode == null) {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DataChangeService {
|
||||
if (!subscribers.addIfAbsent(subscriber)) {
|
||||
logger.warn("Attempted to add already added subscriber!");
|
||||
} else {
|
||||
logger.trace(
|
||||
logger.debug(
|
||||
() -> {
|
||||
var sources =
|
||||
subscriber.wantedSources.stream()
|
||||
|
||||
@@ -141,12 +141,25 @@ public class Logger {
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String message, LogLevel messageLevel, LogLevel conditionalLevel) {
|
||||
if (shouldLog(conditionalLevel)) {
|
||||
log(message, messageLevel, group, className);
|
||||
}
|
||||
}
|
||||
|
||||
private void log(Supplier<String> messageSupplier, LogLevel level) {
|
||||
if (shouldLog(level)) {
|
||||
log(messageSupplier.get(), level, group, className);
|
||||
}
|
||||
}
|
||||
|
||||
private void log(
|
||||
Supplier<String> messageSupplier, LogLevel messageLevel, LogLevel conditionalLevel) {
|
||||
if (shouldLog(conditionalLevel)) {
|
||||
log(messageSupplier.get(), messageLevel, group, className);
|
||||
}
|
||||
}
|
||||
|
||||
public void error(Supplier<String> messageSupplier) {
|
||||
log(messageSupplier, LogLevel.ERROR);
|
||||
}
|
||||
@@ -155,9 +168,16 @@ public class Logger {
|
||||
log(message, LogLevel.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message with the stack trace of a Throwable. The stacktrace will only be printed
|
||||
* if the current LogLevel is TRACE
|
||||
*
|
||||
* @param message
|
||||
* @param t
|
||||
*/
|
||||
public void error(String message, Throwable t) {
|
||||
log(message, LogLevel.ERROR);
|
||||
log(convertStackTraceToString(t), LogLevel.ERROR);
|
||||
log(convertStackTraceToString(t), LogLevel.ERROR, LogLevel.TRACE);
|
||||
}
|
||||
|
||||
public void warn(Supplier<String> messageSupplier) {
|
||||
|
||||
@@ -42,8 +42,7 @@ public class TimedTaskManager {
|
||||
Thread thread = defaultThreadFactory.newThread(r);
|
||||
thread.setUncaughtExceptionHandler(
|
||||
(t, e) -> {
|
||||
logger.error("TimedTask threw uncaught exception!");
|
||||
e.printStackTrace();
|
||||
logger.error("TimedTask threw uncaught exception!", e);
|
||||
});
|
||||
return thread;
|
||||
}
|
||||
@@ -75,8 +74,7 @@ public class TimedTaskManager {
|
||||
}
|
||||
|
||||
if (throwable != null) {
|
||||
logger.error("TimedTask threw uncaught exception!");
|
||||
throwable.printStackTrace();
|
||||
logger.error("TimedTask threw uncaught exception!", throwable);
|
||||
// Restart the runnable again
|
||||
execute(runnable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user