26 #ifndef STATICLIB_PION_LOGGER_HPP
27 #define STATICLIB_PION_LOGGER_HPP
29 #include "staticlib/config.hpp"
31 #if defined(STATICLIB_PION_DISABLE_LOGGING)
33 #define STATICLIB_PION_LOG_DEBUG(LOG, MSG) { if (LOG) {} }
34 #define STATICLIB_PION_LOG_INFO(LOG, MSG) { if (LOG) {} }
35 #define STATICLIB_PION_LOG_WARN(LOG, MSG) { if (LOG) {} }
36 #define STATICLIB_PION_LOG_ERROR(LOG, MSG) { if (LOG) {} }
37 #define STATICLIB_PION_LOG_FATAL(LOG, MSG) { if (LOG) {} }
39 #elif defined(STATICLIB_PION_USE_WILTON_LOGGING)
44 #include "wilton/wilton_logging.h"
58 inline void log(
const std::string& name,
const std::string& level,
const std::string& message){
59 wilton_logger_log(level.c_str(),
static_cast<int>(level.length()),
60 name.c_str(),
static_cast<int>(name.length()),
61 message.c_str(),
static_cast<int>(message.length()));
71 inline bool is_priority_enabled(
const std::string& name,
const std::string& level){
73 wilton_logger_is_level_enabled(name.c_str(),
static_cast<int>(name.length()),
74 level.c_str(),
static_cast<int>(level.length()), std::addressof(res));
83 #define STATICLIB_PION_LOG_TO_WILTON(LOG, LEVEL, MSG) \
84 if (logger::is_priority_enabled(LOG, LEVEL)) { \
85 std::ostringstream ostream; \
87 logger::log(LOG, LEVEL, ostream.str()); \
90 #define STATICLIB_PION_LOG_DEBUG(LOG, MSG) STATICLIB_PION_LOG_TO_WILTON(LOG, "DEBUG", MSG)
91 #define STATICLIB_PION_LOG_INFO(LOG, MSG) STATICLIB_PION_LOG_TO_WILTON(LOG, "INFO", MSG)
92 #define STATICLIB_PION_LOG_WARN(LOG, MSG) STATICLIB_PION_LOG_TO_WILTON(LOG, "WARN", MSG)
93 #define STATICLIB_PION_LOG_ERROR(LOG, MSG) STATICLIB_PION_LOG_TO_WILTON(LOG, "ERROR", MSG)
94 #define STATICLIB_PION_LOG_FATAL(LOG, MSG) STATICLIB_PION_LOG_TO_WILTON(LOG, "FATAL", MSG)
104 #define STATICLIB_PION_LOG_TO_OSTREAM(LOG, LEVEL, MSG) \
105 { std::cout << std::time(nullptr) << ' ' << std::this_thread::get_id() << ' ' << LEVEL << ' ' << LOG << ' ' << MSG << std::endl; }
107 #define STATICLIB_PION_LOG_DEBUG(LOG, MSG) STATICLIB_PION_LOG_TO_OSTREAM(LOG, "DEBUG", MSG)
108 #define STATICLIB_PION_LOG_INFO(LOG, MSG) STATICLIB_PION_LOG_TO_OSTREAM(LOG, "INFO", MSG)
109 #define STATICLIB_PION_LOG_WARN(LOG, MSG) STATICLIB_PION_LOG_TO_OSTREAM(LOG, "WARN", MSG)
110 #define STATICLIB_PION_LOG_ERROR(LOG, MSG) STATICLIB_PION_LOG_TO_OSTREAM(LOG, "ERROR", MSG)
111 #define STATICLIB_PION_LOG_FATAL(LOG, MSG) STATICLIB_PION_LOG_TO_OSTREAM(LOG, "FATAL", MSG)
115 #endif // STATICLIB_PION_LOGGER_HPP