mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2026-04-04 16:27:07 +02:00
Feature: Allow setting the log level for the different modules at runtime
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "defaults.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <LittleFS.h>
|
||||
#include <esp_log.h>
|
||||
#include <nvs_flash.h>
|
||||
|
||||
#undef TAG
|
||||
@@ -153,6 +154,15 @@ bool ConfigurationClass::write()
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject logging = doc["logging"].to<JsonObject>();
|
||||
logging["default"] = config.Logging.Default;
|
||||
JsonArray modules = logging["modules"].to<JsonArray>();
|
||||
for (uint8_t i = 0; i < LOG_MODULE_COUNT; i++) {
|
||||
JsonObject module = modules.add<JsonObject>();
|
||||
module["level"] = config.Logging.Modules[i].Level;
|
||||
module["name"] = config.Logging.Modules[i].Name;
|
||||
}
|
||||
|
||||
if (!Utils::checkJsonAlloc(doc, __FUNCTION__, __LINE__)) {
|
||||
return false;
|
||||
}
|
||||
@@ -329,6 +339,15 @@ bool ConfigurationClass::read()
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject logging = doc["logging"];
|
||||
config.Logging.Default = logging["default"] | ESP_LOG_ERROR;
|
||||
JsonArray modules = logging["modules"];
|
||||
for (uint8_t i = 0; i < LOG_MODULE_COUNT; i++) {
|
||||
JsonObject module = modules[i].as<JsonObject>();
|
||||
strlcpy(config.Logging.Modules[i].Name, module["name"] | "", sizeof(config.Logging.Modules[i].Name));
|
||||
config.Logging.Modules[i].Level = module["level"] | ESP_LOG_VERBOSE;
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
// Check for default DTU serial
|
||||
@@ -426,6 +445,12 @@ void ConfigurationClass::migrate()
|
||||
}
|
||||
}
|
||||
|
||||
if (config.Cfg.Version < 0x00011e00) {
|
||||
config.Logging.Default = ESP_LOG_VERBOSE;
|
||||
strlcpy(config.Logging.Modules[0].Name, "CORE", sizeof(config.Logging.Modules[0].Name));
|
||||
config.Logging.Modules[0].Level = ESP_LOG_ERROR;
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
config.Cfg.Version = CONFIG_VERSION;
|
||||
@@ -487,6 +512,17 @@ void ConfigurationClass::deleteInverterById(const uint8_t id)
|
||||
}
|
||||
}
|
||||
|
||||
int8_t ConfigurationClass::getIndexForLogModule(const String& moduleName) const
|
||||
{
|
||||
for (uint8_t i = 0; i < LOG_MODULE_COUNT; i++) {
|
||||
if (strcmp(config.Logging.Modules[i].Name, moduleName.c_str()) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ConfigurationClass::loop()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(sWriterMutex);
|
||||
|
||||
Reference in New Issue
Block a user