Added Set Log Level Commands
This commit is contained in:
@@ -1005,9 +1005,76 @@ void CommandHandler::handleSystemCommand(JsonVariant contents, const MessageCont
|
||||
handleGetFirmwareStatusCommand(context);
|
||||
} else if (action == "set_network_config") {
|
||||
handleSetNetworkConfigCommand(contents, context);
|
||||
} else if (action == "set_serial_log_level") {
|
||||
handleSetSerialLogLevelCommand(contents, context);
|
||||
} else if (action == "set_sd_log_level") {
|
||||
handleSetSdLogLevelCommand(contents, context);
|
||||
} else {
|
||||
LOG_WARNING("Unknown system action: %s", action.c_str());
|
||||
sendErrorResponse("system", "Unknown action: " + action, context);
|
||||
}
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// LOG LEVEL COMMANDS
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
void CommandHandler::handleSetSerialLogLevelCommand(JsonVariant contents, const MessageContext& context) {
|
||||
if (!contents.containsKey("level")) {
|
||||
sendErrorResponse("set_serial_log_level", "Missing level parameter", context);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t level = contents["level"].as<uint8_t>();
|
||||
|
||||
// Set the level in ConfigManager
|
||||
if (_configManager.setSerialLogLevel(level)) {
|
||||
// Apply the level to Logging immediately
|
||||
Logging::setLevel((Logging::LogLevel)level);
|
||||
|
||||
// Save to SD card
|
||||
bool saved = _configManager.saveGeneralConfig();
|
||||
|
||||
if (saved) {
|
||||
sendSuccessResponse("set_serial_log_level",
|
||||
"Serial log level set to " + String(level) + " and saved", context);
|
||||
LOG_INFO("Serial log level updated to %d", level);
|
||||
} else {
|
||||
sendErrorResponse("set_serial_log_level",
|
||||
"Log level set but failed to save to SD card", context);
|
||||
LOG_ERROR("Failed to save serial log level to SD card");
|
||||
}
|
||||
} else {
|
||||
sendErrorResponse("set_serial_log_level",
|
||||
"Invalid log level (must be 0-5)", context);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandHandler::handleSetSdLogLevelCommand(JsonVariant contents, const MessageContext& context) {
|
||||
if (!contents.containsKey("level")) {
|
||||
sendErrorResponse("set_sd_log_level", "Missing level parameter", context);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t level = contents["level"].as<uint8_t>();
|
||||
|
||||
// Set the level in ConfigManager
|
||||
if (_configManager.setSdLogLevel(level)) {
|
||||
// Save to SD card
|
||||
bool saved = _configManager.saveGeneralConfig();
|
||||
|
||||
if (saved) {
|
||||
sendSuccessResponse("set_sd_log_level",
|
||||
"SD log level set to " + String(level) + " and saved", context);
|
||||
LOG_INFO("SD log level updated to %d (not yet implemented)", level);
|
||||
} else {
|
||||
sendErrorResponse("set_sd_log_level",
|
||||
"Log level set but failed to save to SD card", context);
|
||||
LOG_ERROR("Failed to save SD log level to SD card");
|
||||
}
|
||||
} else {
|
||||
sendErrorResponse("set_sd_log_level",
|
||||
"Invalid log level (must be 0-5)", context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,4 +139,8 @@ private:
|
||||
|
||||
// System Config
|
||||
void handleResetDefaultsCommand(const MessageContext& context);
|
||||
|
||||
// Log Level Commands
|
||||
void handleSetSerialLogLevelCommand(JsonVariant contents, const MessageContext& context);
|
||||
void handleSetSdLogLevelCommand(JsonVariant contents, const MessageContext& context);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user