Macro-based debug trace system with optional SD file logging. More...
#include <cstdio>
#include <cstdarg>
#include <ctime>
#include <string>
#include <cstring>
#include "framework_config.h"
#include "storage/StorageManager.h"
#include "framework/AppContext.h"
#include "time/TimeManager.h"
Go to the source code of this file.
Macros | |
#define | TRACE_LVL_INFO 0 |
#define | TRACE_LVL_WARN 1 |
#define | TRACE_LVL_ERROR 2 |
#define | TRACE_INCLUDE_TIMESTAMP 1 |
#define | TRACE_INIT(MODULE_NAME) |
Declare trace usage in a source file for a given module. | |
#define | TRACEF(level, ...) |
Core trace macro with level support. | |
#define | TRACE(...) TRACEF(TRACE_LVL_INFO, __VA_ARGS__) |
Default trace (INFO level). | |
#define | TRACE_WARN(...) TRACEF(TRACE_LVL_WARN, __VA_ARGS__) |
WARN level trace. | |
#define | TRACE_ERROR(...) TRACEF(TRACE_LVL_ERROR, __VA_ARGS__) |
ERROR level trace. | |
Enumerations | |
enum | TraceTimeFormat { TRACE_TIME_UTC , TRACE_TIME_LOCAL } |
Functions | |
void | setTraceOutputToFile (StorageManager *sm, const std::string &path) |
Set trace output to SD file using FatFsStorageManager. | |
const char * | traceLevelToString (int level) |
Convert trace level to string. | |
void | shortenFilePath (const char *fullPath, char *buffer, size_t maxLen) |
Strip file path to filename only. | |
std::string | getFormattedTimestamp () |
Internal trace log handler. | |
void | traceLog (const char *module, int level, const char *file, int line, const char *func, const char *format,...) |
Internal trace log function. | |
Variables | |
static std::string | tracePath |
static bool | traceToFile = false |
static TraceTimeFormat | traceTimeFormat = TRACE_TIME_LOCAL |
Part of the PicoFramework application framework. Provides compile-time enabled, level-filtered trace logging for embedded applications. Features:
TRACE_<MODULE>
in framework_config.h)TRACE_LEVEL_MIN
)Controlled via framework_config.h
. SD output is enabled if TRACE_USE_SD
is set to 1.
Definition in file DebugTrace.h.
#define TRACE | ( | ... | ) | TRACEF(TRACE_LVL_INFO, __VA_ARGS__) |
Definition at line 187 of file DebugTrace.h.
#define TRACE_ERROR | ( | ... | ) | TRACEF(TRACE_LVL_ERROR, __VA_ARGS__) |
Definition at line 197 of file DebugTrace.h.
#define TRACE_INCLUDE_TIMESTAMP 1 |
Definition at line 39 of file DebugTrace.h.
#define TRACE_INIT | ( | MODULE_NAME | ) |
Definition at line 170 of file DebugTrace.h.
#define TRACE_LVL_ERROR 2 |
Definition at line 36 of file DebugTrace.h.
#define TRACE_LVL_INFO 0 |
Definition at line 34 of file DebugTrace.h.
#define TRACE_LVL_WARN 1 |
Definition at line 35 of file DebugTrace.h.
#define TRACE_WARN | ( | ... | ) | TRACEF(TRACE_LVL_WARN, __VA_ARGS__) |
Definition at line 192 of file DebugTrace.h.
#define TRACEF | ( | level, | |
... | |||
) |
Definition at line 177 of file DebugTrace.h.
enum TraceTimeFormat |
Enumerator | |
---|---|
TRACE_TIME_UTC | |
TRACE_TIME_LOCAL |
Definition at line 84 of file DebugTrace.h.
|
inline |
Formats and dispatches output.
Definition at line 95 of file DebugTrace.h.
References TimeManager::currentTimeForTrace(), AppContext::getInstance(), and AppContext::getService().
Referenced by traceLog().
|
inline |
sm | Storage manager (or nullptr for console only) |
path | File path (e.g. "/log/trace.txt") |
Definition at line 51 of file DebugTrace.h.
References tracePath, and traceToFile.
Referenced by FrameworkManager::setupTraceFromConfig().
|
inline |
Definition at line 78 of file DebugTrace.h.
Referenced by traceLog().
|
inline |
Definition at line 60 of file DebugTrace.h.
References TRACE_LVL_ERROR, TRACE_LVL_INFO, and TRACE_LVL_WARN.
Referenced by traceLog().
|
inline |
module | Module name (e.g. "Network") |
level | Trace level (TRACE_LVL_INFO, TRACE_LVL_WARN, TRACE_LVL_ERROR) |
file | Source file name |
line | Source line number |
func | Function name |
format | Format string for the message |
Definition at line 127 of file DebugTrace.h.
References StorageManager::appendToFile(), getFormattedTimestamp(), AppContext::getInstance(), AppContext::getService(), shortenFilePath(), TRACE_LEVEL_MIN, traceLevelToString(), tracePath, and traceToFile.
|
inlinestatic |
Definition at line 43 of file DebugTrace.h.
Referenced by setTraceOutputToFile(), and traceLog().
|
static |
Definition at line 89 of file DebugTrace.h.
|
inlinestatic |
Definition at line 44 of file DebugTrace.h.
Referenced by setTraceOutputToFile(), and traceLog().