55void setup_log(std::map<std::string, severity_level> threshold) {
59 [](boost::log::record_view
const& rec, boost::log::formatting_ostream& strm) {
61 if (
auto v = boost::log::extract<boost::posix_time::ptime>(
"TimeStamp", rec)) {
66 new boost::posix_time::time_facet(
"%H:%M:%s")
69 strm << v.get() <<
" ";
72 if (
auto v = boost::log::extract<boost::log::thread_id>(
"ThreadID", rec)) {
73 strm <<
"T:" << v.get() <<
" ";
76 if (
auto v = boost::log::extract<severity_level>(
"Severity", rec)) {
77 strm << log_color_table[static_cast<std::size_t>(v.get())];
78 strm <<
"S:" << std::setw(7) << std::left << v.get() <<
" ";
80 if (
auto v = boost::log::extract<channel>(
"Channel", rec)) {
81 strm <<
"C:" << std::setw(5) << std::left << v.get() <<
" ";
84 if (
auto v = boost::log::extract<std::string>(
"MqttFile", rec)) {
85 strm << boost::filesystem::path(v.get()).filename().string() <<
":";
87 if (
auto v = boost::log::extract<unsigned int>(
"MqttLine", rec)) {
88 strm << v.get() <<
" ";
90 if (
auto v = boost::log::extract<void const*>(
"MqttAddress", rec)) {
91 strm <<
"A:" << v.get() <<
" ";
95 if (
auto v = boost::log::extract<std::string>(
"MqttFunction", rec)) {
99 strm << rec[boost::log::expressions::smessage];
104 boost::shared_ptr<std::ostream> stream(&std::clog, boost::null_deleter());
106 using text_sink = boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend>;
107 auto sink = boost::make_shared<text_sink>();
108 sink->locked_backend()->add_stream(stream);
109 sink->set_formatter(fmt);
112 [threshold = force_move(threshold)]
113 (boost::log::attribute_value_set
const& avs) {
116 auto chan = boost::log::extract<channel>(
"Channel", avs);
117 auto sev = boost::log::extract<severity_level>(
"Severity", avs);
119 auto it = threshold.find(chan.get());
120 if (it == threshold.end())
return false;
121 return sev.get() >= it->second;
127 boost::log::core::get()->set_filter(fil);
128 boost::log::core::get()->add_sink(sink);
130 boost::log::add_common_attributes();