Feature: Redirect all ESP log output to the MessageOutput handler

This commit is contained in:
Thomas Basler
2025-04-18 15:01:01 +02:00
parent 98e6d05e4e
commit 724890147f
3 changed files with 17 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ public:
size_t write(const uint8_t* buffer, size_t size) override;
void register_ws_output(AsyncWebSocket* output);
static int log_vprintf(const char *fmt, va_list arguments);
private:
void loop();

View File

@@ -31,6 +31,13 @@ build_flags =
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
-DEMC_TASK_STACK_SIZE=6400
; -DHOY_DEBUG_QUEUE
; Log related defines
-DUSE_ESP_IDF_LOG
-DLOG_LOCAL_LEVEL=5
-DCORE_DEBUG_LEVEL=5
-DTAG="\"CORE\""
-Wall -Wextra -Wunused -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference
; Have to remove -Werror because of
; https://github.com/espressif/arduino-esp32/issues/9044 and

View File

@@ -19,6 +19,7 @@ void MessageOutputClass::init(Scheduler& scheduler)
{
scheduler.addTask(_loopTask);
_loopTask.enable();
esp_log_set_vprintf(log_vprintf);
}
void MessageOutputClass::register_ws_output(AsyncWebSocket* output)
@@ -28,6 +29,13 @@ void MessageOutputClass::register_ws_output(AsyncWebSocket* output)
_ws = output;
}
int MessageOutputClass::log_vprintf(const char* fmt, va_list arguments)
{
char log_buffer[WS_CHUNK_SIZE_BYTES];
vsnprintf(log_buffer, sizeof(log_buffer), fmt, arguments);
return MessageOutput.print(log_buffer);
}
void MessageOutputClass::serialWrite(MessageOutputClass::message_t const& m)
{
// operator bool() of HWCDC returns false if the device is not attached to