8 #ifndef WPIUTIL_WPI_LOGGER_H_ 9 #define WPIUTIL_WPI_LOGGER_H_ 13 #include "wpi/SmallString.h" 14 #include "wpi/raw_ostream.h" 19 WPI_LOG_CRITICAL = 50,
32 typedef std::function<void(
unsigned int level,
const char* file,
33 unsigned int line,
const char* msg)>
37 explicit Logger(
const LogFunc& func) : m_func(func) {}
38 Logger(
const LogFunc& func,
unsigned int min_level)
39 : m_func(func), m_min_level(min_level) {}
41 void SetLogger(LogFunc func) { m_func = func; }
43 void set_min_level(
unsigned int level) { m_min_level = level; }
44 unsigned int min_level()
const {
return m_min_level; }
46 void Log(
unsigned int level,
const char* file,
unsigned int line,
48 if (!m_func || level < m_min_level)
return;
49 m_func(level, file, line, msg);
52 bool HasLogger()
const {
return m_func !=
nullptr; }
56 unsigned int m_min_level = 20;
59 #define WPI_LOG(logger_inst, level, x) \ 61 ::wpi::Logger& WPI_logger_ = logger_inst; \ 62 if (WPI_logger_.min_level() <= level && WPI_logger_.HasLogger()) { \ 63 ::wpi::SmallString<128> log_buf_; \ 64 ::wpi::raw_svector_ostream log_os_{log_buf_}; \ 66 WPI_logger_.Log(level, __FILE__, __LINE__, log_buf_.c_str()); \ 70 #define WPI_ERROR(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_ERROR, x) 71 #define WPI_WARNING(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_WARNING, x) 72 #define WPI_INFO(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_INFO, x) 75 #define WPI_DEBUG(inst, x) \ 78 #define WPI_DEBUG1(inst, x) \ 81 #define WPI_DEBUG2(inst, x) \ 84 #define WPI_DEBUG3(inst, x) \ 87 #define WPI_DEBUG4(inst, x) \ 91 #define WPI_DEBUG(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG, x) 92 #define WPI_DEBUG1(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG1, x) 93 #define WPI_DEBUG2(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG2, x) 94 #define WPI_DEBUG3(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG3, x) 95 #define WPI_DEBUG4(inst, x) WPI_LOG(inst, ::wpi::WPI_LOG_DEBUG4, x) 100 #endif // WPIUTIL_WPI_LOGGER_H_ namespace to hold default to_json function
Definition: json_binary_writer.cpp:39