-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wpiutil, wpilib] Add FileLogger and log console to DataLog
- Loading branch information
Showing
11 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
DLM_GetLog | ||
DLM_GetLogDir | ||
DLM_Log | ||
DLM_LogConsoleOutput | ||
DLM_LogNetworkTables | ||
DLM_SignalNewDSDataOccur | ||
DLM_Start | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, key); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
WPIUtilJNI.freeFileLogger(m_impl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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. | ||
|
||
#include "wpi/FileLogger.h" | ||
|
||
namespace wpi { | ||
FileLogger::FileLogger(std::string_view file, | ||
std::function<void(std::string_view)> callback) | ||
#ifdef __linux__ | ||
: m_fileHandle{open(file.data(), O_RDONLY)}, | ||
m_inotifyHandle{inotify_init()}, | ||
m_inotifyWatchHandle{ | ||
inotify_add_watch(m_inotifyHandle, file.data(), IN_MODIFY)}, | ||
m_thread{[=, this] { | ||
char buf[4000]; | ||
struct inotify_event ev; | ||
int len = 0; | ||
while ((len = read(m_inotifyHandle, &ev, sizeof(ev))) > 0) { | ||
int bufLen = 0; | ||
if ((bufLen = read(m_fileHandle, buf, sizeof(buf)) > 0)) { | ||
callback(std::string_view{buf, bufLen}); | ||
} | ||
} | ||
}} | ||
#endif | ||
{ | ||
} | ||
FileLogger::~FileLogger() { | ||
#ifdef __linux__ | ||
inotify_rm_watch(m_inotifyHandle, m_inotifyWatchHandle); | ||
close(m_inotifyHandle); | ||
close(m_fileHandle); | ||
m_thread.join(); | ||
#endif | ||
} | ||
} // namespace wpi |
Oops, something went wrong.