From ae1b6fc67b139890b11c07ba66a2ddad4c31dc8a Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 10 Oct 2023 09:48:11 +0200 Subject: [PATCH] Weblog json dynamic --- src/web/WebLogService.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/web/WebLogService.cpp b/src/web/WebLogService.cpp index 69b90153a..d3fe63729 100644 --- a/src/web/WebLogService.cpp +++ b/src/web/WebLogService.cpp @@ -174,17 +174,21 @@ char * WebLogService::messagetime(char * out, const uint64_t t, const size_t buf strlcpy(out, uuid::log::format_timestamp_ms(t, 3).c_str(), bufsize); } else { time_t t1 = time_offset_ + t / 1000ULL; - strftime(out, bufsize, "%F %T", localtime(&t1)); - snprintf(out, bufsize, "%s.%03d", out, (uint16_t)(t % 1000)); + char timestr[bufsize]; + strftime(timestr, bufsize, "%F %T", localtime(&t1)); + snprintf(out, bufsize, "%s.%03d", timestr, (uint16_t)(t % 1000)); } return out; } // send to web eventsource void WebLogService::transmit(const QueuedLogMessage & message) { - StaticJsonDocument jsonDocument; - JsonObject logEvent = jsonDocument.to(); - char time_string[25]; + DynamicJsonDocument jsonDocument(EMSESP_JSON_SIZE_LARGE); + if (jsonDocument.capacity() == 0) { + return; + } + JsonObject logEvent = jsonDocument.to(); + char time_string[25]; logEvent["t"] = messagetime(time_string, message.content_->uptime_ms, sizeof(time_string)); logEvent["l"] = message.content_->level;