Macro to trace log all MeshPackets as JSON (#4336)

* Macro to trace log all MeshPackets as JSON

* Comment

* Add trace logging to file for native target

* bytes to hex

* Add time_ms

---------

Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
This commit is contained in:
Ben Meadors
2024-07-28 19:49:10 -05:00
committed by GitHub
parent 8b0208d1c6
commit 811a9ae261
7 changed files with 113 additions and 6 deletions

View File

@@ -17,6 +17,7 @@
std::map<configNames, int> settingsMap;
std::map<configNames, std::string> settingsStrings;
std::ofstream traceFile;
char *configPath = nullptr;
// FIXME - move setBluetoothEnable into a HALPlatform class
@@ -134,7 +135,9 @@ void portduinoSetup()
try {
if (yamlConfig["Logging"]) {
if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "debug") {
if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "trace") {
settingsMap[logoutputlevel] = level_trace;
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "debug") {
settingsMap[logoutputlevel] = level_debug;
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "info") {
settingsMap[logoutputlevel] = level_info;
@@ -143,6 +146,7 @@ void portduinoSetup()
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "error") {
settingsMap[logoutputlevel] = level_error;
}
settingsStrings[traceFilename] = yamlConfig["Logging"]["TraceFile"].as<std::string>("");
}
if (yamlConfig["Lora"]) {
settingsMap[use_sx1262] = false;
@@ -346,6 +350,14 @@ void portduinoSetup()
if (settingsStrings[spidev] != "") {
SPI.begin(settingsStrings[spidev].c_str());
}
if (settingsStrings[traceFilename] != "") {
try {
traceFile.open(settingsStrings[traceFilename], std::ios::out | std::ios::app);
} catch (std::ofstream::failure &e) {
std::cout << "*** traceFile Exception " << e.what() << std::endl;
exit(EXIT_FAILURE);
}
}
return;
}