Dokumentace, upravy pro barevne zvyrazneni
This commit is contained in:
parent
be3f935575
commit
b240ceca67
14
README.md
14
README.md
@ -1,3 +1,15 @@
|
|||||||
# Trace
|
# Trace
|
||||||
|
|
||||||
Knihovna Trace (Stopař) pro ESP8266
|
Knihovna Trace (Stopař) pro ESP8266/ESP32.
|
||||||
|
|
||||||
|
![Screenshot](doc/traceSerial.png)
|
||||||
|
|
||||||
|
## Konfigurace
|
||||||
|
|
||||||
|
Konfiguracni makra jsou:
|
||||||
|
|
||||||
|
Logovani do weboveho soketu ma prioritu pred logovanim na seriovy port!
|
||||||
|
|
||||||
|
* `-DTRACE_USE_ASYNC_WEBSOCKET` - TRACE vystup pouziva webovy soket v ESPAsyncWebServer knihovne
|
||||||
|
* `-DTRACE_LOG_COLORS` - pro ESP8266 a `DEBUG_ESP_PORT` umoznuje barevne zvyraznene logovani na seriovy port.
|
||||||
|
* `-DTRACE_LIMIT=TRACE_VERBOSE` - umozni nastavit uroven logovani
|
BIN
doc/traceSerial.png
Normal file
BIN
doc/traceSerial.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
68
src/trace.h
68
src/trace.h
@ -38,16 +38,16 @@
|
|||||||
#if defined(TRACE_USE_ASYNC_WEBSOCKET)
|
#if defined(TRACE_USE_ASYNC_WEBSOCKET)
|
||||||
#include "asyncWebsocket/traceAsyncWebsocket.hpp"
|
#include "asyncWebsocket/traceAsyncWebsocket.hpp"
|
||||||
#define TRACEPLUS(when, severity, ...) \
|
#define TRACEPLUS(when, severity, ...) \
|
||||||
{ \
|
do { \
|
||||||
if (when > 0) \
|
if (when > 0) \
|
||||||
TRACE(severity, __VA_ARGS__) \
|
TRACE(severity, __VA_ARGS__) \
|
||||||
}
|
} while (0)
|
||||||
#define TRACE(severity, text, ...) \
|
#define TRACE(severity, text, ...) \
|
||||||
{ \
|
do { \
|
||||||
constexpr bool trace_limit = (severity <= TRACE_LIMIT); \
|
constexpr bool trace_limit = (severity <= TRACE_LIMIT); \
|
||||||
if (trace_limit) \
|
if (trace_limit) \
|
||||||
trace_print(severity, PSTR(text), ##__VA_ARGS__); \
|
trace_print(severity, PSTR(text), ##__VA_ARGS__); \
|
||||||
}
|
} while (0)
|
||||||
#define TRACEFUNC(severity, ...) trace_printfunc(severity, __func__, __FILE__, TOSTRING(__LINE__), __VA_ARGS__)
|
#define TRACEFUNC(severity, ...) trace_printfunc(severity, __func__, __FILE__, TOSTRING(__LINE__), __VA_ARGS__)
|
||||||
#define TRACEDUMP(severity, prefix, address, size) trace_dump(severity, prefix, address, size)
|
#define TRACEDUMP(severity, prefix, address, size) trace_dump(severity, prefix, address, size)
|
||||||
#define TRACE_INIT(a) trace_init()
|
#define TRACE_INIT(a) trace_init()
|
||||||
@ -59,7 +59,7 @@
|
|||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#define TRACE(severity, format, ...) \
|
#define TRACE(severity, format, ...) \
|
||||||
{ \
|
do { \
|
||||||
constexpr int s = severity; \
|
constexpr int s = severity; \
|
||||||
if (s == TRACE_ERROR) \
|
if (s == TRACE_ERROR) \
|
||||||
log_e(format, ##__VA_ARGS__); \
|
log_e(format, ##__VA_ARGS__); \
|
||||||
@ -71,24 +71,66 @@
|
|||||||
log_i(format, ##__VA_ARGS__); \
|
log_i(format, ##__VA_ARGS__); \
|
||||||
else if (s == TRACE_VERBOSE) \
|
else if (s == TRACE_VERBOSE) \
|
||||||
log_v(format, ##__VA_ARGS__); \
|
log_v(format, ##__VA_ARGS__); \
|
||||||
}
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#ifdef DEBUG_ESP_PORT
|
#ifdef DEBUG_ESP_PORT
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// following is inspired by macros, used in ESP-IDF log_x()
|
||||||
|
#ifndef TRACE_LOG_COLORS
|
||||||
|
#define TRACE_LOG_COLORS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TRACE_LOG_COLORS
|
||||||
|
#define TRACE_LOG_COLOR_BLACK "30"
|
||||||
|
#define TRACE_LOG_COLOR_RED "31" // ERROR
|
||||||
|
#define TRACE_LOG_COLOR_GREEN "32" // INFO
|
||||||
|
#define TRACE_LOG_COLOR_YELLOW "33" // WARNING
|
||||||
|
#define TRACE_LOG_COLOR_BLUE "34"
|
||||||
|
#define TRACE_LOG_COLOR_MAGENTA "35"
|
||||||
|
#define TRACE_LOG_COLOR_CYAN "36" // DEBUG
|
||||||
|
#define TRACE_LOG_COLOR_GRAY "37" // VERBOSE
|
||||||
|
#define TRACE_LOG_COLOR_WHITE "38"
|
||||||
|
|
||||||
|
#define TRACE_LOG_COLOR(COLOR) "\033[0;" COLOR "m"
|
||||||
|
#define TRACE_LOG_BOLD(COLOR) "\033[1;" COLOR "m"
|
||||||
|
#define TRACE_LOG_RESET_COLOR "\033[0m"
|
||||||
|
|
||||||
|
#define TRACE_LOG_COLOR_E TRACE_LOG_COLOR(TRACE_LOG_COLOR_RED)
|
||||||
|
#define TRACE_LOG_COLOR_W TRACE_LOG_COLOR(TRACE_LOG_COLOR_YELLOW)
|
||||||
|
#define TRACE_LOG_COLOR_I TRACE_LOG_COLOR(TRACE_LOG_COLOR_GREEN)
|
||||||
|
#define TRACE_LOG_COLOR_D TRACE_LOG_COLOR(TRACE_LOG_COLOR_CYAN)
|
||||||
|
#define TRACE_LOG_COLOR_V TRACE_LOG_COLOR(TRACE_LOG_COLOR_GRAY)
|
||||||
|
#define TRACE_LOG_COLOR_PRINT(letter) log_printf(TRACE_LOG_COLOR_##letter)
|
||||||
|
#define TRACE_LOG_COLOR_PRINT_END log_printf(TRACE_LOG_RESET_COLOR)
|
||||||
|
#else
|
||||||
|
#define TRACE_LOG_COLOR_E
|
||||||
|
#define TRACE_LOG_COLOR_W
|
||||||
|
#define TRACE_LOG_COLOR_I
|
||||||
|
#define TRACE_LOG_COLOR_D
|
||||||
|
#define TRACE_LOG_COLOR_V
|
||||||
|
#define TRACE_LOG_RESET_COLOR
|
||||||
|
#define TRACE_LOG_COLOR_PRINT(letter)
|
||||||
|
#define TRACE_LOG_COLOR_PRINT_END
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TRACE_SHORT_LOG_FORMAT(letter, format) PSTR(TRACE_LOG_COLOR_##letter format TRACE_LOG_RESET_COLOR "\n")
|
||||||
|
#define TRACE_LOG_FORMAT(letter, format) PSTR(TRACE_LOG_COLOR_##letter "[%8lu][" #letter "] " format TRACE_LOG_RESET_COLOR "\n"), millis()
|
||||||
|
|
||||||
#define TRACE(severity, text, ...) \
|
#define TRACE(severity, text, ...) \
|
||||||
{ \
|
do { \
|
||||||
constexpr int s = severity; \
|
constexpr int s = severity; \
|
||||||
if (s == TRACE_ERROR) \
|
if (s == TRACE_ERROR) \
|
||||||
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [E] " text "\n"), millis(), ##__VA_ARGS__); \
|
DEBUG_ESP_PORT.printf_P(TRACE_LOG_FORMAT(E, text), ##__VA_ARGS__); \
|
||||||
else if (s == TRACE_DEBUG) \
|
else if (s == TRACE_DEBUG) \
|
||||||
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [D] " text "\n"), millis(), ##__VA_ARGS__); \
|
DEBUG_ESP_PORT.printf_P(TRACE_LOG_FORMAT(D, text), ##__VA_ARGS__); \
|
||||||
else if (s == TRACE_WARNING) \
|
else if (s == TRACE_WARNING) \
|
||||||
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [W] " text "\n"), millis(), ##__VA_ARGS__); \
|
DEBUG_ESP_PORT.printf_P(TRACE_LOG_FORMAT(W, text), ##__VA_ARGS__); \
|
||||||
else if (s == TRACE_INFO) \
|
else if (s == TRACE_INFO) \
|
||||||
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [I] " text "\n"), millis(), ##__VA_ARGS__); \
|
DEBUG_ESP_PORT.printf_P(TRACE_LOG_FORMAT(I, text), ##__VA_ARGS__); \
|
||||||
else if (s == TRACE_VERBOSE) \
|
else if (s == TRACE_VERBOSE) \
|
||||||
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [V] " text "\n"), millis(), ##__VA_ARGS__); \
|
DEBUG_ESP_PORT.printf_P(TRACE_LOG_FORMAT(V, text), ##__VA_ARGS__); \
|
||||||
}
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#warning TRACE output is disabled!
|
#warning TRACE output is disabled!
|
||||||
#define TRACE(...) ((void) 0) // from assert.h "NOP" - http://stackoverflow.com/questions/9187628/c-empty-function-macros
|
#define TRACE(...) ((void) 0) // from assert.h "NOP" - http://stackoverflow.com/questions/9187628/c-empty-function-macros
|
||||||
|
Loading…
Reference in New Issue
Block a user