Skip to content

Commit

Permalink
also log MF logs to WPI data logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dejabot committed Nov 12, 2023
1 parent e2e35a8 commit 04ddf13
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/com/team766/logging/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

import com.team766.config.ConfigFileReader;
import com.team766.library.CircularBuffer;
import edu.wpi.first.wpilibj.DataLogManager;

public final class Logger {

private static final boolean ALSO_LOG_TO_DATALOG = true;

private static class LogUncaughtException implements Thread.UncaughtExceptionHandler {
public void uncaughtException(final Thread t, final Throwable e) {
e.printStackTrace();
Expand Down Expand Up @@ -96,7 +100,8 @@ public Collection<LogEntry> recentEntries() {
public void logData(final Severity severity, final String format, final Object... args) {
var entry = LogEntry.newBuilder().setTime(getTime()).setSeverity(severity)
.setCategory(m_category);
entry.setMessageStr(String.format(format, args));
String message = String.format(format, args);
entry.setMessageStr(message);
m_recentEntries.add(entry.build());
entry.setMessageStr(format);
for (Object arg : args) {
Expand All @@ -105,6 +110,7 @@ public void logData(final Severity severity, final String format, final Object..
if (m_logWriter != null) {
m_logWriter.logStoredFormat(entry);
}
if (ALSO_LOG_TO_DATALOG) DataLogManager.log(message);
}

public void logRaw(final Severity severity, final String message) {
Expand All @@ -114,6 +120,7 @@ public void logRaw(final Severity severity, final String message) {
if (m_logWriter != null) {
m_logWriter.log(entry);
}
if (ALSO_LOG_TO_DATALOG) DataLogManager.log(message);
}

void logOnlyInMemory(final Severity severity, final String message) {
Expand Down

0 comments on commit 04ddf13

Please sign in to comment.