5#ifndef WPIUTIL_WPI_LOGGER_H_
6#define WPIUTIL_WPI_LOGGER_H_
29 using LogFunc = std::function<void(
unsigned int level,
const char*
file,
30 unsigned int line,
const char* msg)>;
40 unsigned int min_level()
const {
return m_min_level; }
42 void DoLog(
unsigned int level,
const char*
file,
unsigned int line,
45 void LogV(
unsigned int level,
const char*
file,
unsigned int line,
48 template <
typename... Args>
49 void Log(
unsigned int level,
const char*
file,
unsigned int line,
51 if (m_func && level >= m_min_level) {
56 bool HasLogger()
const {
return m_func !=
nullptr; }
60 unsigned int m_min_level = 20;
66#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
69#define WPI_LOG(logger_inst, level, format, ...) \
70 if ((logger_inst).HasLogger() && level >= (logger_inst).min_level()) { \
72 .Log(level, __FILE__, __LINE__, \
73 FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \
76#define WPI_ERROR(inst, format, ...) \
77 WPI_LOG(inst, ::wpi::WPI_LOG_ERROR, format __VA_OPT__(, ) __VA_ARGS__)
78#define WPI_WARNING(inst, format, ...) \
79 WPI_LOG(inst, ::wpi::WPI_LOG_WARNING, format __VA_OPT__(, ) __VA_ARGS__)
80#define WPI_INFO(inst, format, ...) \
81 WPI_LOG(inst, ::wpi::WPI_LOG_INFO, format __VA_OPT__(, ) __VA_ARGS__)
82#define WPI_DEBUG(inst, format, ...) \
83 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG, format __VA_OPT__(, ) __VA_ARGS__)
84#define WPI_DEBUG1(inst, format, ...) \
85 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG1, format __VA_OPT__(, ) __VA_ARGS__)
86#define WPI_DEBUG2(inst, format, ...) \
87 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG2, format __VA_OPT__(, ) __VA_ARGS__)
88#define WPI_DEBUG3(inst, format, ...) \
89 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG3, format __VA_OPT__(, ) __VA_ARGS__)
90#define WPI_DEBUG4(inst, format, ...) \
91 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG4, format __VA_OPT__(, ) __VA_ARGS__)
then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file
Definition: ThirdPartyNotices.txt:192
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Definition: Logger.h:30
void Log(unsigned int level, const char *file, unsigned int line, fmt::string_view format, Args &&... args)
Definition: Logger.h:49
void LogV(unsigned int level, const char *file, unsigned int line, fmt::string_view format, fmt::format_args args)
Logger(LogFunc func, unsigned int min_level)
Definition: Logger.h:34
void set_min_level(unsigned int level)
Definition: Logger.h:39
bool HasLogger() const
Definition: Logger.h:56
Logger(LogFunc func)
Definition: Logger.h:33
unsigned int min_level() const
Definition: Logger.h:40
void SetLogger(LogFunc func)
Definition: Logger.h:37
void DoLog(unsigned int level, const char *file, unsigned int line, const char *msg)
basic_string_view< char > string_view
Definition: core.h:501
constexpr auto make_format_args(T &... args) -> format_arg_store< Context, remove_cvref_t< T >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1824
basic_format_args< format_context > format_args
An alias to basic_format_args<format_context>.
Definition: core.h:1971
Definition: ntcore_cpp.h:26
LogLevel
Definition: Logger.h:15
@ WPI_LOG_CRITICAL
Definition: Logger.h:16
@ WPI_LOG_DEBUG2
Definition: Logger.h:22
@ WPI_LOG_DEBUG
Definition: Logger.h:20
@ WPI_LOG_ERROR
Definition: Logger.h:17
@ WPI_LOG_DEBUG1
Definition: Logger.h:21
@ WPI_LOG_DEBUG4
Definition: Logger.h:24
@ WPI_LOG_WARNING
Definition: Logger.h:18
@ WPI_LOG_DEBUG3
Definition: Logger.h:23
@ WPI_LOG_INFO
Definition: Logger.h:19
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:108