Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
log WPILogs to flash only, not console.
Browse files Browse the repository at this point in the history
  • Loading branch information
dejabot committed Mar 30, 2024
1 parent 3e6afee commit 5ec1db8
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/java/com/team766/logging/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import com.team766.config.ConfigFileReader;
import com.team766.library.CircularBuffer;
import edu.wpi.first.util.datalog.StringLogEntry;
import edu.wpi.first.wpilibj.DataLogManager;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.concurrent.atomic.AtomicReference;

public final class Logger {

private static boolean alsoLogToDataLog = false;
private static AtomicReference<StringLogEntry> wpiLogEntryReference =
new AtomicReference<StringLogEntry>();

private static class LogUncaughtException implements Thread.UncaughtExceptionHandler {
public void uncaughtException(final Thread t, final Throwable e) {
Expand Down Expand Up @@ -73,7 +76,12 @@ public void uncaughtException(final Thread t, final Throwable e) {
}

public static void enableLoggingToDataLog(boolean enabled) {
alsoLogToDataLog = enabled;
if (enabled) {
wpiLogEntryReference.compareAndSet(
null, new StringLogEntry(DataLogManager.getLog(), "/maroon/logs"));
} else {
wpiLogEntryReference.set(null);
}
}

public static Logger get(final Category category) {
Expand All @@ -99,7 +107,7 @@ private Logger(final Category category) {
}

public static boolean isLoggingToDataLog() {
return alsoLogToDataLog;
return wpiLogEntryReference.get() != null;
}

public Collection<LogEntry> recentEntries() {
Expand All @@ -125,8 +133,9 @@ public void logData(final Severity severity, final String format, final Object..
if (m_logWriter != null) {
m_logWriter.logStoredFormat(entry);
}
if (alsoLogToDataLog && (severity.compareTo(Severity.INFO) >= 0)) {
DataLogManager.log(message);
StringLogEntry stringLogEntry = wpiLogEntryReference.get();
if (stringLogEntry != null && (severity.compareTo(Severity.INFO) >= 0)) {
stringLogEntry.append(message);
}
}

Expand All @@ -142,8 +151,9 @@ public void logRaw(final Severity severity, final String message) {
if (m_logWriter != null) {
m_logWriter.log(entry);
}
if (alsoLogToDataLog && (severity.compareTo(Severity.INFO) >= 0)) {
DataLogManager.log(message);
StringLogEntry stringLogEntry = wpiLogEntryReference.get();
if (stringLogEntry != null && (severity.compareTo(Severity.INFO) >= 0)) {
stringLogEntry.append(message);
}
}

Expand Down

0 comments on commit 5ec1db8

Please sign in to comment.