7#if !defined(ASYNC_MQTT_UTIL_LOG_HPP)
8#define ASYNC_MQTT_UTIL_LOG_HPP
14#if defined(ASYNC_MQTT_USE_LOG)
16#include <boost/log/core.hpp>
17#include <boost/log/attributes.hpp>
18#include <boost/log/attributes/scoped_attribute.hpp>
19#include <boost/log/expressions.hpp>
20#include <boost/log/expressions/keyword.hpp>
21#include <boost/log/sources/global_logger_storage.hpp>
22#include <boost/log/sources/severity_channel_logger.hpp>
23#include <boost/log/trivial.hpp>
24#include <boost/log/utility/manipulators/add_value.hpp>
25#include <boost/log/utility/setup/common_attributes.hpp>
26#include <boost/log/utility/setup/console.hpp>
27#include <boost/preprocessor/if.hpp>
28#include <boost/preprocessor/cat.hpp>
29#include <boost/preprocessor/comparison/greater_equal.hpp>
39struct channel : std::string {
40 using std::string::string;
63 constexpr char const*
const str[] {
71 o << str[static_cast<std::size_t>(sev)];
78 template <
typename... Params>
79 explicit constexpr null_log(Params&&...) {}
83inline constexpr null_log
const&
operator<<(null_log
const& o, T
const&) {
return o; }
87#if defined(ASYNC_MQTT_USE_LOG)
91using global_logger_type = boost::log::sources::severity_channel_logger<severity_level, channel>;
92inline global_logger_type& logger() {
93 thread_local global_logger_type l;
98BOOST_LOG_ATTRIBUTE_KEYWORD(file,
"MqttFile", std::string)
99BOOST_LOG_ATTRIBUTE_KEYWORD(line,
"MqttLine",
unsigned int)
100BOOST_LOG_ATTRIBUTE_KEYWORD(function,
"MqttFunction", std::string)
101BOOST_LOG_ATTRIBUTE_KEYWORD(address,
"MqttAddress",
void const*)
105#define ASYNC_MQTT_LOG_FP(chan, sev) \
106 BOOST_LOG_STREAM_CHANNEL_SEV(async_mqtt::logger(), async_mqtt::channel(chan), sev) \
107 << boost::log::add_value(async_mqtt::file, __FILE__) \
108 << boost::log::add_value(async_mqtt::line, __LINE__) \
109 << boost::log::add_value(async_mqtt::function, BOOST_CURRENT_FUNCTION)
111#define ASYNC_MQTT_GET_LOG_SEV_NUM(lv) BOOST_PP_CAT(ASYNC_MQTT_, lv)
117#if !defined(ASYNC_MQTT_LOG_SEV)
118#define ASYNC_MQTT_LOG_SEV trace
121#define ASYNC_MQTT_trace 0
122#define ASYNC_MQTT_debug 1
123#define ASYNC_MQTT_info 2
124#define ASYNC_MQTT_warning 3
125#define ASYNC_MQTT_error 4
126#define ASYNC_MQTT_fatal 5
132#if !defined(ASYNC_MQTT_LOG)
134#define ASYNC_MQTT_LOG(chan, sev) \
136 BOOST_PP_GREATER_EQUAL(ASYNC_MQTT_GET_LOG_SEV_NUM(sev), ASYNC_MQTT_GET_LOG_SEV_NUM(ASYNC_MQTT_LOG_SEV)), \
137 ASYNC_MQTT_LOG_FP(chan, async_mqtt::severity_level::sev), \
138 async_mqtt::detail::null_log(chan, async_mqtt::severity_level::sev) \
143#if !defined(ASYNC_MQTT_ADD_VALUE)
145#define ASYNC_MQTT_ADD_VALUE(name, val) boost::log::add_value((async_mqtt::name), (val))
151#if !defined(ASYNC_MQTT_LOG)
153#define ASYNC_MQTT_LOG(chan, sev) async_mqtt::detail::null_log(chan, async_mqtt::severity_level::sev)
157#if !defined(ASYNC_MQTT_ADD_VALUE)
159#define ASYNC_MQTT_ADD_VALUE(name, val) val
severity_level
Definition log.hpp:53
@ trace
trace level for detaied behavior and reporting issue
@ warning
warning level such as timeout
@ debug
debug level not used in async_mqtt, so far
@ info
info level api call is output
@ error
error level error report such as connection is failed
@ fatal
fatal level it is logic error of async_mqtt
std::ostream & operator<<(std::ostream &o, mqtt_error v)
output to the stream