feat: releay ui example, simplify logging
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "core/ApiServer.h"
|
||||
#include "core/TaskManager.h"
|
||||
#include "Service.h"
|
||||
#include "util/Logging.h"
|
||||
|
||||
class Spore {
|
||||
public:
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
enum class LogLevel {
|
||||
DEBUG = 0,
|
||||
INFO = 1,
|
||||
WARN = 2,
|
||||
ERROR = 3
|
||||
};
|
||||
|
||||
struct LogData {
|
||||
LogLevel level;
|
||||
String component;
|
||||
String message;
|
||||
unsigned long timestamp;
|
||||
|
||||
LogData(LogLevel lvl, const String& comp, const String& msg)
|
||||
: level(lvl), component(comp), message(msg), timestamp(millis()) {}
|
||||
};
|
||||
|
||||
class LoggingService : public Service {
|
||||
public:
|
||||
LoggingService(NodeContext& ctx, ApiServer& apiServer);
|
||||
virtual ~LoggingService() = default;
|
||||
|
||||
// Service interface
|
||||
void registerEndpoints(ApiServer& api) override;
|
||||
const char* getName() const override { return "logging"; }
|
||||
|
||||
// Logging methods
|
||||
void log(LogLevel level, const String& component, const String& message);
|
||||
void debug(const String& component, const String& message);
|
||||
void info(const String& component, const String& message);
|
||||
void warn(const String& component, const String& message);
|
||||
void error(const String& component, const String& message);
|
||||
|
||||
// Configuration
|
||||
void setLogLevel(LogLevel level);
|
||||
void enableSerialLogging(bool enable);
|
||||
|
||||
private:
|
||||
NodeContext& ctx;
|
||||
ApiServer& apiServer;
|
||||
LogLevel currentLogLevel;
|
||||
bool serialLoggingEnabled;
|
||||
|
||||
void setupEventHandlers();
|
||||
void handleSerialLog(void* data);
|
||||
String formatLogMessage(const LogData& logData);
|
||||
String logLevelToString(LogLevel level);
|
||||
|
||||
// API endpoint handlers
|
||||
void handleGetLogLevel(AsyncWebServerRequest* request);
|
||||
void handleSetLogLevel(AsyncWebServerRequest* request);
|
||||
void handleGetConfig(AsyncWebServerRequest* request);
|
||||
};
|
||||
|
||||
// Global logging functions that use the event system directly
|
||||
void logDebug(NodeContext& ctx, const String& component, const String& message);
|
||||
void logInfo(NodeContext& ctx, const String& component, const String& message);
|
||||
void logWarn(NodeContext& ctx, const String& component, const String& message);
|
||||
void logError(NodeContext& ctx, const String& component, const String& message);
|
||||
|
||||
// Convenience macros for easy logging (requires ctx to be available)
|
||||
#define LOG_DEBUG(ctx, component, message) logDebug(ctx, component, message)
|
||||
#define LOG_INFO(ctx, component, message) logInfo(ctx, component, message)
|
||||
#define LOG_WARN(ctx, component, message) logWarn(ctx, component, message)
|
||||
#define LOG_ERROR(ctx, component, message) logError(ctx, component, message)
|
||||
@@ -32,6 +32,11 @@ public:
|
||||
unsigned long restart_delay_ms;
|
||||
uint16_t json_doc_size;
|
||||
|
||||
// Memory Management
|
||||
uint32_t low_memory_threshold_bytes;
|
||||
uint32_t critical_memory_threshold_bytes;
|
||||
size_t max_concurrent_http_requests;
|
||||
|
||||
// Constructor
|
||||
Config();
|
||||
};
|
||||
29
include/spore/util/Logging.h
Normal file
29
include/spore/util/Logging.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
enum class LogLevel {
|
||||
DEBUG = 0,
|
||||
INFO = 1,
|
||||
WARN = 2,
|
||||
ERROR = 3
|
||||
};
|
||||
|
||||
// Global log level - can be changed at runtime
|
||||
extern LogLevel g_logLevel;
|
||||
|
||||
// Simple logging functions
|
||||
void logMessage(LogLevel level, const String& component, const String& message);
|
||||
void logDebug(const String& component, const String& message);
|
||||
void logInfo(const String& component, const String& message);
|
||||
void logWarn(const String& component, const String& message);
|
||||
void logError(const String& component, const String& message);
|
||||
|
||||
// Set global log level
|
||||
void setLogLevel(LogLevel level);
|
||||
|
||||
// Convenience macros - no context needed
|
||||
#define LOG_DEBUG(component, message) logDebug(component, message)
|
||||
#define LOG_INFO(component, message) logInfo(component, message)
|
||||
#define LOG_WARN(component, message) logWarn(component, message)
|
||||
#define LOG_ERROR(component, message) logError(component, message)
|
||||
Reference in New Issue
Block a user