[wpiutil, wpilib] Add FileLogger and log console output (#6977)

This commit is contained in:
Gold856
2024-09-13 01:13:06 -04:00
committed by GitHub
parent 32252f7d6a
commit 3bbbf86632
12 changed files with 428 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.util;
import edu.wpi.first.util.datalog.DataLog;
/**
* A class version of `tail -f`, otherwise known as `tail -f` at home. Watches a file and puts the
* data into a data log. Only works on Linux-based platforms.
*/
public class FileLogger implements AutoCloseable {
private final long m_impl;
/**
* Construct a FileLogger. When the specified file is modified, appended data will be appended to
* the specified data log.
*
* @param file The path to the file.
* @param log A data log.
* @param key The log key to append data to.
*/
public FileLogger(String file, DataLog log, String key) {
m_impl = WPIUtilJNI.createFileLogger(file, log.getImpl(), key);
}
@Override
public void close() {
WPIUtilJNI.freeFileLogger(m_impl);
}
}

View File

@@ -217,6 +217,24 @@ public class WPIUtilJNI {
public static native int[] waitForObjectsTimeout(int[] handles, double timeout)
throws InterruptedException;
/**
* Create a native FileLogger. When the specified file is modified, appended data will be appended
* to the specified data log.
*
* @param file path to the file
* @param log data log implementation handle
* @param key log key to append data to
* @return The FileLogger handle.
*/
public static native long createFileLogger(String file, long log, String key);
/**
* Free a native FileLogger. This causes the FileLogger to stop appending data to the log.
*
* @param fileTail The FileLogger handle.
*/
public static native void freeFileLogger(long fileTail);
/** Utility class. */
protected WPIUtilJNI() {}
}