Various logging cleanups (#65)

* Various logging cleanups

* Move device info to string, apply spotless
This commit is contained in:
Banks T
2020-07-28 21:20:54 -04:00
committed by GitHub
parent a349f1cee6
commit 48851470ae
10 changed files with 49 additions and 48 deletions

View File

@@ -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) {

View File

@@ -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()

View File

@@ -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) {

View File

@@ -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);
}