34#define TRACE_LVL_INFO 0
35#define TRACE_LVL_WARN 1
36#define TRACE_LVL_ERROR 2
38#ifndef TRACE_INCLUDE_TIMESTAMP
39#define TRACE_INCLUDE_TIMESTAMP 1
80 const char *slash = strrchr(fullPath,
'/');
81 snprintf(buffer, maxLen,
"%s", slash ? slash + 1 : fullPath);
97 static bool timeAvailable =
false;
103 timeAvailable = tm !=
nullptr;
114 return std::string(
"");
127inline void traceLog(
const char *module,
int level,
const char *file,
int line,
const char *func,
const char *format, ...)
137 va_start(args, format);
138 vsnprintf(msgBuf,
sizeof(msgBuf), format, args);
140 std::string formatted;
141 std::string timestamp =
"";
143#if TRACE_INCLUDE_TIMESTAMP
147 module + "] " + fileBuf + ":" + std::to_string(line) +
148 " (" + func + "): " + msgBuf + "\n";
156 storage->
appendToFile(
tracePath,
reinterpret_cast<const uint8_t *
>(formatted.c_str()), formatted.length());
162 fputs(formatted.c_str(), stdout);
170#define TRACE_INIT(MODULE_NAME) \
171 static constexpr const char *TRACE_MODULE = #MODULE_NAME; \
172 static constexpr int TRACE_ENABLED = TRACE_##MODULE_NAME;
177#define TRACEF(level, ...) \
180 if (TRACE_ENABLED && (level) >= TRACE_LEVEL_MIN) \
181 traceLog(TRACE_MODULE, level, __FILE__, __LINE__, __func__, __VA_ARGS__); \
187#define TRACE(...) TRACEF(TRACE_LVL_INFO, __VA_ARGS__)
192#define TRACE_WARN(...) TRACEF(TRACE_LVL_WARN, __VA_ARGS__)
197#define TRACE_ERROR(...) TRACEF(TRACE_LVL_ERROR, __VA_ARGS__)
static std::string tracePath
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.
const char * traceLevelToString(int level)
Convert trace level to string.
void setTraceOutputToFile(StorageManager *sm, const std::string &path)
Set trace output to SD file using FatFsStorageManager.
static TraceTimeFormat traceTimeFormat
Abstract interface for file and directory storage backends.
static AppContext & getInstance()
Abstract base class for storage access and file operations.
virtual bool appendToFile(const std::string &path, const uint8_t *data, size_t size)=0
Append data to a file.
std::string currentTimeForTrace() const
Get the current time formatted as a string.
Delegates to user or system configuration.