Trace/src/trace.h

103 lines
4.3 KiB
C
Raw Normal View History

2018-04-22 15:48:16 +02:00
/**
* @file trace.h
* @author Pavel Brychta, http://www.xpablo.cz
*
* Copyright (c) 2016-24 Pavel Brychta. All rights reserved.
2018-04-22 15:48:16 +02:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
2023-05-20 12:47:13 +02:00
#pragma once
2018-04-22 15:48:16 +02:00
// Definice jednotlivych typu hlaseni do trasovani
#define TRACE_NONE -1 // nic
#define TRACE_ERROR 0 // chybova zprava = cervena
#define TRACE_WARNING 1 // varovani - zluta
#define TRACE_INFO 2 // informacni zprava - zelena
#define TRACE_DEBUG 3 // ladici zprava - cerna
#define TRACE_VERBOSE 4 // mene zajimava ladici zprava - take cerna
#ifndef TRACE_LIMIT
#define TRACE_LIMIT TRACE_DEBUG
#endif
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#if defined(TRACE_USE_ASYNC_WEBSOCKET)
#include "asyncWebsocket/traceAsyncWebsocket.hpp"
#define TRACEPLUS(when, severity, ...) \
{ \
if (when > 0) \
TRACE(severity, __VA_ARGS__) \
}
#define TRACE(severity, text, ...) \
{ \
constexpr bool trace_limit = (severity <= TRACE_LIMIT); \
if (trace_limit) \
trace_print(severity, PSTR(text), ##__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 TRACE_INIT(a) trace_init()
#define TRACE_ADDWEB(srv) trace_addweb(srv)
#define TRACE_FORCEUPDATE(a) trace_forceupdate()
#else
#define TRACEPLUS(...) ((void) 0)
#if defined(ESP32)
#include <Arduino.h>
#define TRACE(severity, format, ...) \
{ \
constexpr int s = severity; \
if (s == TRACE_ERROR) \
log_e(format, ##__VA_ARGS__); \
else if (s == TRACE_DEBUG) \
log_d(format, ##__VA_ARGS__); \
else if (s == TRACE_WARNING) \
log_w(format, ##__VA_ARGS__); \
else if (s == TRACE_INFO) \
log_i(format, ##__VA_ARGS__); \
else if (s == TRACE_VERBOSE) \
log_v(format, ##__VA_ARGS__); \
}
#else
#ifdef DEBUG_ESP_PORT
#include <Arduino.h>
#define TRACE(severity, text, ...) \
{ \
constexpr int s = severity; \
if (s == TRACE_ERROR) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [E] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_DEBUG) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [D] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_WARNING) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [W] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_INFO) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [I] " text "\n"), millis(), ##__VA_ARGS__); \
else if (s == TRACE_VERBOSE) \
DEBUG_ESP_PORT.printf_P(PSTR("%8ld [V] " text "\n"), millis(), ##__VA_ARGS__); \
}
#else
#warning TRACE output is disabled!
#define TRACE(...) ((void) 0) // from assert.h "NOP" - http://stackoverflow.com/questions/9187628/c-empty-function-macros
#endif
#endif
#define TRACEFUNC(...) ((void) 0)
#define TRACEDUMP(...) ((void) 0)
#define TRACE_INIT(a) ((void) 0)
#define TRACE_ADDWEB(a) ((void) 0)
#define TRACE_FORCEUPDATE(a) ((void) 0)
#endif