|
|
@ -2,6 +2,14 @@
|
|
|
|
#ifndef _TRACE_H
|
|
|
|
#ifndef _TRACE_H
|
|
|
|
#define _TRACE_H
|
|
|
|
#define _TRACE_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#ifdef _TRACE_USE_FMT
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
|
@ -33,5 +41,35 @@ const char* trace_name_of(enum trace_level lv);
|
|
|
|
extern const char* const _TRACE_CONTROL_ENV_NAME;
|
|
|
|
extern const char* const _TRACE_CONTROL_ENV_NAME;
|
|
|
|
extern const char* const _trace_level_descriptions[_TRACE_LEVEL_NUM];
|
|
|
|
extern const char* const _trace_level_descriptions[_TRACE_LEVEL_NUM];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _TRACE_USE_FMT
|
|
|
|
|
|
|
|
namespace Trace {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: How to get caller info?
|
|
|
|
|
|
|
|
template<trace_level Level, size_t N, typename... Args>
|
|
|
|
|
|
|
|
inline constexpr void printf(const char (&msg)[N], Args&&... pack) {
|
|
|
|
|
|
|
|
if (Level >= trace_max_level()) { fmt::vprint(stderr, msg, fmt::make_format_args(std::forward<Args>(pack)...)); std::putc('\n', stderr); };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _TRACE_L(level, name) template<size_t N, typename... Args> \
|
|
|
|
|
|
|
|
inline constexpr void name(const char (&msg)[N], Args&&... pack) \
|
|
|
|
|
|
|
|
{ ::Trace::printf<TRACE_LEVEL_ ## level >(msg, std::forward<Args>(pack)...); }
|
|
|
|
|
|
|
|
_TRACE_L(DEBUG, Debug);
|
|
|
|
|
|
|
|
_TRACE_L(DEBUG, Trace);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_TRACE_L(INFO, Info);
|
|
|
|
|
|
|
|
_TRACE_L(WARN, Warn);
|
|
|
|
|
|
|
|
_TRACE_L(ERROR, Error);
|
|
|
|
|
|
|
|
template<size_t N, typename... Args>
|
|
|
|
|
|
|
|
[[noreturn]]
|
|
|
|
|
|
|
|
inline constexpr void Fatal(const char (&msg)[N], Args&&... pack)
|
|
|
|
|
|
|
|
{ ::Trace::printf<TRACE_LEVEL_FATAL >(msg, std::forward<Args>(pack)...);
|
|
|
|
|
|
|
|
::std::terminate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef _TRACE_L
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _TRACE_H */
|
|
|
|
#endif /* _TRACE_H */
|
|
|
|