diff --git a/include/MessageOutput.h b/include/MessageOutput.h index 850facb9..0f06e7db 100644 --- a/include/MessageOutput.h +++ b/include/MessageOutput.h @@ -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(); diff --git a/platformio.ini b/platformio.ini index 4df46eda..587e46ba 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/MessageOutput.cpp b/src/MessageOutput.cpp index d836b77b..d54a11eb 100644 --- a/src/MessageOutput.cpp +++ b/src/MessageOutput.cpp @@ -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