|
| 1 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 2 | +// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#ifdef ASYNCWEBSERVER_LOG_CUSTOM |
| 7 | + |
| 8 | +// The user must provide the following macros in AsyncWebServerLoggingCustom.h: |
| 9 | +// async_ws_log_e, async_ws_log_w, async_ws_log_i, async_ws_log_d, async_ws_log_v |
| 10 | +#include <AsyncWebServerLoggingCustom.h> |
| 11 | + |
| 12 | +// Build-time checks to ensure required macros are defined |
| 13 | +#ifndef async_ws_log_e |
| 14 | +#error "AsyncWebServerLoggingCustom.h must define async_ws_log_e" |
| 15 | +#endif |
| 16 | + |
| 17 | +#ifndef async_ws_log_w |
| 18 | +#error "AsyncWebServerLoggingCustom.h must define async_ws_log_w" |
| 19 | +#endif |
| 20 | + |
| 21 | +#ifndef async_ws_log_i |
| 22 | +#error "AsyncWebServerLoggingCustom.h must define async_ws_log_i" |
| 23 | +#endif |
| 24 | + |
| 25 | +#ifndef async_ws_log_d |
| 26 | +#error "AsyncWebServerLoggingCustom.h must define async_ws_log_d" |
| 27 | +#endif |
| 28 | + |
| 29 | +#ifndef async_ws_log_v |
| 30 | +#error "AsyncWebServerLoggingCustom.h must define async_ws_log_v" |
| 31 | +#endif |
| 32 | + |
| 33 | +#else // ASYNCWEBSERVER_LOG_CUSTOM |
| 34 | + |
| 35 | +/** |
| 36 | + * LibreTiny specific configurations |
| 37 | + */ |
| 38 | +#if defined(LIBRETINY) |
| 39 | +#include <Arduino.h> |
| 40 | +#define async_ws_log_e(format, ...) log_e(format, ##__VA_ARGS__) |
| 41 | +#define async_ws_log_w(format, ...) log_w(format, ##__VA_ARGS__) |
| 42 | +#define async_ws_log_i(format, ...) log_i(format, ##__VA_ARGS__) |
| 43 | +#define async_ws_log_d(format, ...) log_d(format, ##__VA_ARGS__) |
| 44 | +#define async_ws_log_v(format, ...) log_v(format, ##__VA_ARGS__) |
| 45 | + |
| 46 | +/** |
| 47 | + * Raspberry Pi Pico specific configurations |
| 48 | + */ |
| 49 | +#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) |
| 50 | +#include <HardwareSerial.h> |
| 51 | +// define log levels |
| 52 | +#define ASYNC_WS_LOG_NONE 0 /*!< No log output */ |
| 53 | +#define ASYNC_WS_LOG_ERROR 1 /*!< Critical errors, software module can not recover on its own */ |
| 54 | +#define ASYNC_WS_LOG_WARN 2 /*!< Error conditions from which recovery measures have been taken */ |
| 55 | +#define ASYNC_WS_LOG_INFO 3 /*!< Information messages which describe normal flow of events */ |
| 56 | +#define ASYNC_WS_LOG_DEBUG 4 /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */ |
| 57 | +#define ASYNC_WS_LOG_VERBOSE 5 /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */ |
| 58 | +#define ASYNC_WS_LOG_MAX 6 /*!< Number of levels supported */ |
| 59 | +// set default log level |
| 60 | +#ifndef ASYNCWEBSERVER_LOG_LEVEL |
| 61 | +#define ASYNCWEBSERVER_LOG_LEVEL ASYNC_WS_LOG_WARN |
| 62 | +#endif |
| 63 | +// error |
| 64 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_ERROR |
| 65 | +#define async_ws_log_e(format, ...) Serial.print("E async_ws: " format, ##__VA_ARGS__); |
| 66 | +#else |
| 67 | +#define async_ws_log_e(format, ...) |
| 68 | +#endif |
| 69 | +// warn |
| 70 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_WARN |
| 71 | +#define async_ws_log_w(format, ...) Serial.print("W async_ws: " format, ##__VA_ARGS__); |
| 72 | +#else |
| 73 | +#define async_ws_log_w(format, ...) |
| 74 | +#endif |
| 75 | +// info |
| 76 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_INFO |
| 77 | +#define async_ws_log_i(format, ...) Serial.print("I async_ws: " format, ##__VA_ARGS__); |
| 78 | +#else |
| 79 | +#define async_ws_log_i(format, ...) |
| 80 | +#endif |
| 81 | +// debug |
| 82 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_DEBUG |
| 83 | +#define async_ws_log_d(format, ...) Serial.print("D async_ws: " format, ##__VA_ARGS__); |
| 84 | +#else |
| 85 | +#define async_ws_log_d(format, ...) |
| 86 | +#endif |
| 87 | +// verbose |
| 88 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_VERBOSE |
| 89 | +#define async_ws_log_v(format, ...) Serial.print("V async_ws: " format, ##__VA_ARGS__); |
| 90 | +#else |
| 91 | +#define async_ws_log_v(format, ...) |
| 92 | +#endif |
| 93 | + |
| 94 | +/** |
| 95 | + * ESP8266 specific configurations |
| 96 | + */ |
| 97 | +#elif defined(ESP8266) |
| 98 | +#include <ets_sys.h> |
| 99 | +// define log levels |
| 100 | +#define ASYNC_WS_LOG_NONE 0 /*!< No log output */ |
| 101 | +#define ASYNC_WS_LOG_ERROR 1 /*!< Critical errors, software module can not recover on its own */ |
| 102 | +#define ASYNC_WS_LOG_WARN 2 /*!< Error conditions from which recovery measures have been taken */ |
| 103 | +#define ASYNC_WS_LOG_INFO 3 /*!< Information messages which describe normal flow of events */ |
| 104 | +#define ASYNC_WS_LOG_DEBUG 4 /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */ |
| 105 | +#define ASYNC_WS_LOG_VERBOSE 5 /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */ |
| 106 | +#define ASYNC_WS_LOG_MAX 6 /*!< Number of levels supported */ |
| 107 | +// set default log level |
| 108 | +#ifndef ASYNCWEBSERVER_LOG_LEVEL |
| 109 | +#define ASYNCWEBSERVER_LOG_LEVEL ASYNC_WS_LOG_WARN |
| 110 | +#endif |
| 111 | +// error |
| 112 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_ERROR |
| 113 | +#define async_ws_log_e(format, ...) ets_printf(String(F("E async_ws: " format)).c_str(), ##__VA_ARGS__); |
| 114 | +#else |
| 115 | +#define async_ws_log_e(format, ...) |
| 116 | +#endif |
| 117 | +// warn |
| 118 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_WARN |
| 119 | +#define async_ws_log_w(format, ...) ets_printf(String(F("W async_ws: " format)).c_str(), ##__VA_ARGS__); |
| 120 | +#else |
| 121 | +#define async_ws_log_w(format, ...) |
| 122 | +#endif |
| 123 | +// info |
| 124 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_INFO |
| 125 | +#define async_ws_log_i(format, ...) ets_printf(String(F("I async_ws: " format)).c_str(), ##__VA_ARGS__); |
| 126 | +#else |
| 127 | +#define async_ws_log_i(format, ...) |
| 128 | +#endif |
| 129 | +// debug |
| 130 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_DEBUG |
| 131 | +#define async_ws_log_d(format, ...) ets_printf(String(F("D async_ws: " format)).c_str(), ##__VA_ARGS__); |
| 132 | +#else |
| 133 | +#define async_ws_log_d(format, ...) |
| 134 | +#endif |
| 135 | +// verbose |
| 136 | +#if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_VERBOSE |
| 137 | +#define async_ws_log_v(format, ...) ets_printf(String(F("V async_ws: " format)).c_str(), ##__VA_ARGS__); |
| 138 | +#else |
| 139 | +#define async_ws_log_v(format, ...) |
| 140 | +#endif |
| 141 | + |
| 142 | +/** |
| 143 | + * Arduino specific configurations |
| 144 | + */ |
| 145 | +#elif defined(ARDUINO) |
| 146 | +#if defined(USE_ESP_IDF_LOG) |
| 147 | +#include <esp_log.h> |
| 148 | +#define async_ws_log_e(format, ...) ESP_LOGE("async_ws", format, ##__VA_ARGS__) |
| 149 | +#define async_ws_log_w(format, ...) ESP_LOGW("async_ws", format, ##__VA_ARGS__) |
| 150 | +#define async_ws_log_i(format, ...) ESP_LOGI("async_ws", format, ##__VA_ARGS__) |
| 151 | +#define async_ws_log_d(format, ...) ESP_LOGD("async_ws", format, ##__VA_ARGS__) |
| 152 | +#define async_ws_log_v(format, ...) ESP_LOGV("async_ws", format, ##__VA_ARGS__) |
| 153 | +#else |
| 154 | +#include <esp32-hal-log.h> |
| 155 | +#define async_ws_log_e(format, ...) log_e(format, ##__VA_ARGS__) |
| 156 | +#define async_ws_log_w(format, ...) log_w(format, ##__VA_ARGS__) |
| 157 | +#define async_ws_log_i(format, ...) log_i(format, ##__VA_ARGS__) |
| 158 | +#define async_ws_log_d(format, ...) log_d(format, ##__VA_ARGS__) |
| 159 | +#define async_ws_log_v(format, ...) log_v(format, ##__VA_ARGS__) |
| 160 | +#endif // USE_ESP_IDF_LOG |
| 161 | + |
| 162 | +/** |
| 163 | + * ESP-IDF specific configurations |
| 164 | + */ |
| 165 | +#else |
| 166 | +#include <esp_log.h> |
| 167 | +#define async_ws_log_e(format, ...) ESP_LOGE("async_ws", format, ##__VA_ARGS__) |
| 168 | +#define async_ws_log_w(format, ...) ESP_LOGW("async_ws", format, ##__VA_ARGS__) |
| 169 | +#define async_ws_log_i(format, ...) ESP_LOGI("async_ws", format, ##__VA_ARGS__) |
| 170 | +#define async_ws_log_d(format, ...) ESP_LOGD("async_ws", format, ##__VA_ARGS__) |
| 171 | +#define async_ws_log_v(format, ...) ESP_LOGV("async_ws", format, ##__VA_ARGS__) |
| 172 | +#endif // !LIBRETINY && !ARDUINO |
| 173 | + |
| 174 | +#endif // ASYNCWEBSERVER_LOG_CUSTOM |
0 commit comments