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,
46 fmt::string_view
format, fmt::format_args args);
48 template <
typename... Args>
49 void Log(
unsigned int level,
const char* file,
unsigned int line,
50 fmt::string_view
format, Args&&... args) {
51 if (m_func && level >= m_min_level) {
52 LogV(level, file, line,
format, fmt::make_format_args(args...));
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__, format __VA_OPT__(, ) __VA_ARGS__); \
75#define WPI_ERROR(inst, format, ...) \
76 WPI_LOG(inst, ::wpi::WPI_LOG_ERROR, format __VA_OPT__(, ) __VA_ARGS__)
77#define WPI_WARNING(inst, format, ...) \
78 WPI_LOG(inst, ::wpi::WPI_LOG_WARNING, format __VA_OPT__(, ) __VA_ARGS__)
79#define WPI_INFO(inst, format, ...) \
80 WPI_LOG(inst, ::wpi::WPI_LOG_INFO, format __VA_OPT__(, ) __VA_ARGS__)
81#define WPI_DEBUG(inst, format, ...) \
82 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG, format __VA_OPT__(, ) __VA_ARGS__)
83#define WPI_DEBUG1(inst, format, ...) \
84 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG1, format __VA_OPT__(, ) __VA_ARGS__)
85#define WPI_DEBUG2(inst, format, ...) \
86 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG2, format __VA_OPT__(, ) __VA_ARGS__)
87#define WPI_DEBUG3(inst, format, ...) \
88 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG3, format __VA_OPT__(, ) __VA_ARGS__)
89#define WPI_DEBUG4(inst, format, ...) \
90 WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG4, format __VA_OPT__(, ) __VA_ARGS__)
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
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Definition Logger.h:29
void SetLogger(LogFunc func)
Definition Logger.h:37
void DoLog(unsigned int level, const char *file, unsigned int line, const char *msg)
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
Foonathan namespace.
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