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