Added MQTT Logs, and improved OTA and NTP to Async
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// Forward declaration
|
||||
class MQTTAsyncClient;
|
||||
|
||||
class Logging {
|
||||
public:
|
||||
// Log Levels
|
||||
@@ -28,31 +31,47 @@ public:
|
||||
WARNING = 2, // Warnings and errors
|
||||
INFO = 3, // Info, warnings, and errors
|
||||
DEBUG = 4, // Debug logs. Really high level (full debugging)
|
||||
VERBOSE = 5 // Nearly every command gets printed
|
||||
VERBOSE = 5 // Nearly every command gets printed
|
||||
};
|
||||
|
||||
// MQTT Log Publishing Callback
|
||||
using MqttPublishCallback = std::function<void(const String& topic, const String& payload, int qos)>;
|
||||
|
||||
private:
|
||||
static LogLevel currentLevel;
|
||||
static LogLevel mqttLogLevel;
|
||||
static MqttPublishCallback mqttPublishCallback;
|
||||
static String mqttLogTopic;
|
||||
|
||||
public:
|
||||
// Set the active log level
|
||||
static void setLevel(LogLevel level);
|
||||
|
||||
|
||||
// Get current log level
|
||||
static LogLevel getLevel();
|
||||
|
||||
|
||||
// Set MQTT log level (independent from serial logging)
|
||||
static void setMqttLogLevel(LogLevel level);
|
||||
|
||||
// Get MQTT log level
|
||||
static LogLevel getMqttLogLevel();
|
||||
|
||||
// Set MQTT callback for publishing logs
|
||||
static void setMqttPublishCallback(MqttPublishCallback callback, const String& logTopic);
|
||||
|
||||
// Logging functions
|
||||
static void error(const char* format, ...);
|
||||
static void warning(const char* format, ...);
|
||||
static void info(const char* format, ...);
|
||||
static void debug(const char* format, ...);
|
||||
static void verbose(const char* format, ...);
|
||||
|
||||
|
||||
// Check if level is enabled (for conditional logging)
|
||||
static bool isLevelEnabled(LogLevel level);
|
||||
|
||||
private:
|
||||
static void log(LogLevel level, const char* levelStr, const char* format, va_list args);
|
||||
static void publishToMqtt(LogLevel level, const char* levelStr, const char* message);
|
||||
};
|
||||
|
||||
// Convenience macros for easier use
|
||||
|
||||
Reference in New Issue
Block a user