traceStream and traceAsyncWebSocket are now separate repositories to avoid compile problems without web server
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @file trace.h
|
||||
* @author Pavel Brychta, http://www.xpablo.cz
|
||||
*
|
||||
* Copyright (c) 2016-24 Pavel Brychta. All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Vydefinujeme-li promennou TRACE_ALL=1, pak TRACEPLUS bude vypisovat vsechny zpravy nezavisle od povoleni/zakazani
|
||||
|
||||
// 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)
|
||||
|
||||
class Trace {
|
||||
protected:
|
||||
public:
|
||||
Trace() = default;
|
||||
|
||||
virtual ~Trace() = default;
|
||||
|
||||
virtual void init() {};
|
||||
|
||||
virtual void print(uint8_t severity, const __FlashStringHelper * fmt, ...) {};
|
||||
|
||||
virtual void print(uint8_t severity, const char * fmt, ...) {};
|
||||
|
||||
virtual void dump(uint8_t severity, const char * prefix, const uint8_t * address, size_t size) {};
|
||||
|
||||
virtual void dump(uint8_t severity, const __FlashStringHelper * prefix, const uint8_t * address, size_t size) {};
|
||||
|
||||
virtual void forceupdate() {};
|
||||
};
|
||||
|
||||
extern Trace * mTrace; // Main Trace instance
|
||||
|
||||
#define TRACE(severity, text, ...) \
|
||||
do { \
|
||||
constexpr bool trace_limit = (severity <= TRACE_LIMIT); \
|
||||
if (trace_limit) \
|
||||
if (mTrace) { mTrace->print(severity, PSTR(text), ##__VA_ARGS__); } \
|
||||
} while (0)
|
||||
#define TRACEFUNC(severity, ...) if (mTrace) { mTrace->printfunc(severity, __func__, __FILE__, TOSTRING(__LINE__), __VA_ARGS__); }
|
||||
#define TRACEDUMP(severity, prefix, address, size) if (mTrace) { mTrace->dump(severity, prefix, address, size); }
|
||||
#define TRACE_INIT(a) if (mTrace) { mTrace->init(); }
|
||||
#define TRACE_FORCEUPDATE(a) if (mTrace) { mTrace->forceupdate(); }
|
||||
|
||||
#ifndef TRACE_ALL
|
||||
#define TRACE_ALL 0
|
||||
#endif
|
||||
|
||||
#define TRACEPLUS(when, severity, ...) \
|
||||
do { \
|
||||
constexpr bool handle = (when != 0) || TRACE_ALL; \
|
||||
if (handle) \
|
||||
TRACE(severity, __VA_ARGS__); \
|
||||
} while (0)
|
||||
Reference in New Issue
Block a user