Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Move getLogPath to LoggerUtils
Browse files Browse the repository at this point in the history
uses optional as well for readability
  • Loading branch information
srimanachanta committed Dec 15, 2023
1 parent 55caaf3 commit a6ef8d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.constants.Constants;
import frc.robot.util.LoggerUtil;
import java.nio.file.Path;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
Expand All @@ -24,11 +23,8 @@ public void robotInit() {
switch (Constants.getRobotMode()) {
case REAL:
// Running on a real robot, log to a USB stick
var usbPath = Path.of("/U");
// Check if the USB is plugged in, log to it if so
if (usbPath.toFile().exists()) {
Logger.addDataReceiver(new WPILOGWriter(usbPath.toString()));
}
LoggerUtil.getLogPath()
.ifPresent(p -> Logger.addDataReceiver(new WPILOGWriter(p.toString())));
Logger.addDataReceiver(new NT4Publisher());
break;
case SIM:
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/frc/robot/util/LoggerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import edu.wpi.first.wpilibj.RobotBase;
import frc.generated.BuildConstants;
import frc.robot.constants.Constants;
import java.nio.file.Path;
import java.util.Optional;
import org.littletonrobotics.junction.Logger;

public class LoggerUtil {
Expand All @@ -24,4 +26,20 @@ public static void initializeLoggerMetadata() {
default -> Logger.recordMetadata("GIT_STATUS", "Unknown");
}
}

/**
* Get the path to the logging directory. Returns Empty if the USB drive is not plugged into the
* robot.
*
* @return logging path. Empty if the drive is not plugged in.
*/
public static Optional<Path> getLogPath() {
var usbPath = Path.of("/U");
// Return USB path if it is plugged in
if (usbPath.toFile().exists()) {
return Optional.of(usbPath);
}

return Optional.empty();
}
}

0 comments on commit a6ef8d2

Please sign in to comment.