Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ jobs:
env:
- ci-arduino-rc-asynctcp
- ci-arduino-3-no-json
- ci-arduino-2-esp-idf-log
- ci-arduino-3-esp-idf-log

steps:
- name: Checkout
Expand Down
12 changes: 6 additions & 6 deletions examples/ChunkRetryResponse/ChunkRetryResponse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void setup() {
return 0; // 0 means we are done
}

// log_d("UART answered!");
// async_ws_log_d("UART answered!");

String answer = "You typed: ";
answer.concat((char)key);
Expand All @@ -193,18 +193,18 @@ void setup() {
},
NULL, // upload handler is not used so it should be NULL
[](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
// log_d("Body: index: %u, len: %u, total: %u", index, len, total);
// async_ws_log_d("Body: index: %u, len: %u, total: %u", index, len, total);

if (!index) {
// log_d("Start body parsing");
// async_ws_log_d("Start body parsing");
request->_tempObject = new String();
// cast request->_tempObject pointer to String and reserve total size
((String *)request->_tempObject)->reserve(total);
// set timeout 30s
request->client()->setRxTimeout(30);
}

// log_d("Append body data");
// async_ws_log_d("Append body data");
((String *)request->_tempObject)->concat((const char *)data, len);
}
);
Expand All @@ -217,13 +217,13 @@ void setup() {
void loop() {
if (triggerUART.length() && key == -1) {
Serial.println(triggerUART);
// log_d("Waiting for UART input...");
// async_ws_log_d("Waiting for UART input...");
while (!Serial.available()) {
delay(100);
}
key = Serial.read();
Serial.flush();
// log_d("UART input: %c", key);
// async_ws_log_d("UART input: %c", key);
triggerUART = emptyString;
}
}
20 changes: 20 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ build_flags =
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
; -D CONFIG_ASYNC_TCP_USE_WDT=0
; -D CONFIG_ARDUHAL_LOG_COLORS
; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
; -D USE_ESP_IDF_LOG=1
; -D TAG=\"core\"
; -D LOG_LOCAL_LEVEL=ESP_LOG_VERBOSE
; -D ASYNCWEBSERVER_LOG_DEBUG
upload_protocol = esptool
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, log2file
Expand Down Expand Up @@ -135,6 +141,20 @@ board = ${sysenv.PIO_BOARD}
platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.20-rc2/platform-espressif32.zip
board = ${sysenv.PIO_BOARD}

[env:ci-arduino-2-esp-idf-log]
platform = [email protected]
board = ${sysenv.PIO_BOARD}
build_flags =
${env.build_flags}
-D USE_ESP_IDF_LOG=1
-D TAG=\"core\"

[env:ci-arduino-3-esp-idf-log]
board = ${sysenv.PIO_BOARD}
build_flags =
${env.build_flags}
-D USE_ESP_IDF_LOG=1

[env:ci-arduino-3-no-json]
board = ${sysenv.PIO_BOARD}
lib_deps =
Expand Down
21 changes: 4 additions & 17 deletions src/AsyncEventSource.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov

#include "Arduino.h"
#if defined(ESP32)
#include <rom/ets_sys.h>
#endif
#include "AsyncEventSource.h"
#include "AsyncWebServerLogging.h"

#define ASYNC_SSE_NEW_LINE_CHAR (char)0xa

Expand All @@ -25,9 +22,7 @@ static String generateEventMessage(const char *message, const char *event, uint3
len += 42; // give it some overhead

if (!str.reserve(len)) {
#ifdef ESP32
log_e("Failed to allocate");
#endif
async_ws_log_e("Failed to allocate");
return emptyString;
}

Expand Down Expand Up @@ -201,11 +196,7 @@ AsyncEventSourceClient::~AsyncEventSourceClient() {

bool AsyncEventSourceClient::_queueMessage(const char *message, size_t len) {
if (_messageQueue.size() >= SSE_MAX_QUEUED_MESSAGES) {
#ifdef ESP8266
ets_printf(String(F("ERROR: Too many messages queued\n")).c_str());
#elif defined(ESP32)
log_e("Event message queue overflow: discard message");
#endif
async_ws_log_e("Event message queue overflow: discard message");
return false;
}

Expand All @@ -231,11 +222,7 @@ bool AsyncEventSourceClient::_queueMessage(const char *message, size_t len) {

bool AsyncEventSourceClient::_queueMessage(AsyncEvent_SharedData_t &&msg) {
if (_messageQueue.size() >= SSE_MAX_QUEUED_MESSAGES) {
#ifdef ESP8266
ets_printf(String(F("ERROR: Too many messages queued\n")).c_str());
#elif defined(ESP32)
log_e("Event message queue overflow: discard message");
#endif
async_ws_log_e("Event message queue overflow: discard message");
return false;
}

Expand Down
9 changes: 3 additions & 6 deletions src/AsyncJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov

#include "AsyncJson.h"
#include "AsyncWebServerLogging.h"

#if ASYNC_JSON_SUPPORT == 1

Expand Down Expand Up @@ -123,9 +124,7 @@ void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest *request)
// POST / PUT / ... requests:
// check if JSON body is too large, if it is, don't deserialize
if (request->contentLength() > _maxContentLength) {
#ifdef ESP32
log_e("Content length exceeds maximum allowed");
#endif
async_ws_log_e("Content length exceeds maximum allowed");
request->send(413);
return;
}
Expand Down Expand Up @@ -172,9 +171,7 @@ void AsyncCallbackJsonWebHandler::handleBody(AsyncWebServerRequest *request, uin
if (request->_tempObject == NULL) {
request->_tempObject = calloc(total + 1, sizeof(uint8_t)); // null-terminated string
if (request->_tempObject == NULL) {
#ifdef ESP32
log_e("Failed to allocate");
#endif
async_ws_log_e("Failed to allocate");
request->abort();
return;
}
Expand Down
5 changes: 2 additions & 3 deletions src/AsyncMessagePack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov

#include "AsyncMessagePack.h"
#include "AsyncWebServerLogging.h"

#if ASYNC_MSG_PACK_SUPPORT == 1

Expand Down Expand Up @@ -103,9 +104,7 @@ void AsyncCallbackMessagePackWebHandler::handleBody(AsyncWebServerRequest *reque
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) {
request->_tempObject = malloc(total);
if (request->_tempObject == NULL) {
#ifdef ESP32
log_e("Failed to allocate");
#endif
async_ws_log_e("Failed to allocate");
request->abort();
return;
}
Expand Down
163 changes: 163 additions & 0 deletions src/AsyncWebServerLogging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov

#pragma once

#ifdef ASYNCWEBSERVER_LOG_CUSTOM
// The user must provide the following macros in AsyncWebServerLoggingCustom.h:
// async_ws_log_e, async_ws_log_w, async_ws_log_i, async_ws_log_d, async_ws_log_v
#include <AsyncWebServerLoggingCustom.h>

#elif defined(ASYNCWEBSERVER_LOG_DEBUG)
// Local Debug logging
#include <HardwareSerial.h>
#define async_ws_log_e(format, ...) Serial.printf("E async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#define async_ws_log_w(format, ...) Serial.printf("W async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#define async_ws_log_i(format, ...) Serial.printf("I async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#define async_ws_log_d(format, ...) Serial.printf("D async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#define async_ws_log_v(format, ...) Serial.printf("V async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);

#else
// Framework-based logging

/**
* LibreTiny specific configurations
*/
#if defined(LIBRETINY)
#include <Arduino.h>
#define async_ws_log_e(format, ...) log_e(format, ##__VA_ARGS__)
#define async_ws_log_w(format, ...) log_w(format, ##__VA_ARGS__)
#define async_ws_log_i(format, ...) log_i(format, ##__VA_ARGS__)
#define async_ws_log_d(format, ...) log_d(format, ##__VA_ARGS__)
#define async_ws_log_v(format, ...) log_v(format, ##__VA_ARGS__)

/**
* Raspberry Pi Pico specific configurations
*/
#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
#include <HardwareSerial.h>
// define log levels
#define ASYNC_WS_LOG_NONE 0 /*!< No log output */
#define ASYNC_WS_LOG_ERROR 1 /*!< Critical errors, software module can not recover on its own */
#define ASYNC_WS_LOG_WARN 2 /*!< Error conditions from which recovery measures have been taken */
#define ASYNC_WS_LOG_INFO 3 /*!< Information messages which describe normal flow of events */
#define ASYNC_WS_LOG_DEBUG 4 /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
#define ASYNC_WS_LOG_VERBOSE 5 /*!< Verbose information for debugging purposes */
#define ASYNC_WS_LOG_MAX 6 /*!< Number of levels supported */
// set default log level
#ifndef ASYNCWEBSERVER_LOG_LEVEL
#define ASYNCWEBSERVER_LOG_LEVEL ASYNC_WS_LOG_INFO
#endif
// error
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_ERROR
#define async_ws_log_e(format, ...) Serial.printf("E async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_e(format, ...)
#endif
// warn
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_WARN
#define async_ws_log_w(format, ...) Serial.printf("W async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_w(format, ...)
#endif
// info
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_INFO
#define async_ws_log_i(format, ...) Serial.printf("I async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_i(format, ...)
#endif
// debug
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_DEBUG
#define async_ws_log_d(format, ...) Serial.printf("D async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_d(format, ...)
#endif
// verbose
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_VERBOSE
#define async_ws_log_v(format, ...) Serial.printf("V async_ws %s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_v(format, ...)
#endif

/**
* ESP8266 specific configurations
*/
#elif defined(ESP8266)
#include <ets_sys.h>
// define log levels
#define ASYNC_WS_LOG_NONE 0 /*!< No log output */
#define ASYNC_WS_LOG_ERROR 1 /*!< Critical errors, software module can not recover on its own */
#define ASYNC_WS_LOG_WARN 2 /*!< Error conditions from which recovery measures have been taken */
#define ASYNC_WS_LOG_INFO 3 /*!< Information messages which describe normal flow of events */
#define ASYNC_WS_LOG_DEBUG 4 /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
#define ASYNC_WS_LOG_VERBOSE 5 /*!< Verbose information for debugging purposes */
#define ASYNC_WS_LOG_MAX 6 /*!< Number of levels supported */
// set default log level
#ifndef ASYNCWEBSERVER_LOG_LEVEL
#define ASYNCWEBSERVER_LOG_LEVEL ASYNC_WS_LOG_INFO
#endif
// error
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_ERROR
#define async_ws_log_e(format, ...) ets_printf(String(F("E async_ws %s() %d: " format)).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_e(format, ...)
#endif
// warn
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_WARN
#define async_ws_log_w(format, ...) ets_printf(String(F("W async_ws %s() %d: " format)).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_w(format, ...)
#endif
// info
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_INFO
#define async_ws_log_i(format, ...) ets_printf(String(F("I async_ws %s() %d: " format)).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_i(format, ...)
#endif
// debug
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_DEBUG
#define async_ws_log_d(format, ...) ets_printf(String(F("D async_ws %s() %d: " format)).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_d(format, ...)
#endif
// verbose
#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_VERBOSE
#define async_ws_log_v(format, ...) ets_printf(String(F("V async_ws %s() %d: " format)).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define async_ws_log_v(format, ...)
#endif

/**
* Arduino specific configurations
*/
#elif defined(ARDUINO)
#if defined(USE_ESP_IDF_LOG)
#include <esp_log.h>
#define async_ws_log_e(format, ...) ESP_LOGE("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_w(format, ...) ESP_LOGW("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_i(format, ...) ESP_LOGI("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_d(format, ...) ESP_LOGD("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_v(format, ...) ESP_LOGV("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)

#else
#include <esp32-hal-log.h>
#define async_ws_log_e(format, ...) log_e(format, ##__VA_ARGS__)
#define async_ws_log_w(format, ...) log_w(format, ##__VA_ARGS__)
#define async_ws_log_i(format, ...) log_i(format, ##__VA_ARGS__)
#define async_ws_log_d(format, ...) log_d(format, ##__VA_ARGS__)
#define async_ws_log_v(format, ...) log_v(format, ##__VA_ARGS__)
#endif // USE_ESP_IDF_LOG

/**
* ESP-IDF specific configurations
*/
#else
#include <esp_log.h>
#define async_ws_log_e(format, ...) ESP_LOGE("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_w(format, ...) ESP_LOGW("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_i(format, ...) ESP_LOGI("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_d(format, ...) ESP_LOGD("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define async_ws_log_v(format, ...) ESP_LOGV("async_ws", "%s() %d: " format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif // !LIBRETINY && !ARDUINO

#endif // ASYNCWEBSERVER_LOG_CUSTOM
Loading