22 #include <boost/regex.hpp>
32 std::string remove_ascii_format(
const std::string &in)
35 regex.assign(
"\033\\[.+m(.*)\033\\[0m");
36 std::ostringstream t(std::ios::out | std::ios::binary);
37 std::ostream_iterator<char, char> oi(t);
38 boost::regex_replace(oi, in.begin(), in.end(), regex,
"\\1",
39 boost::match_default | boost::format_sed);
47 void log(
const std::string &log_msg,
int ,
const char * ,
50 auto console = spdlog::get(
"console");
51 auto syslog = spdlog::get(
"syslog");
52 if (!console && !syslog)
54 std::cerr <<
"Logger not set-up yet ! Will display log message as is."
56 std::cerr << log_msg << std::endl;
63 std::string log_msg_with_thread_id = ss.str();
69 console->debug(log_msg_with_thread_id);
71 syslog->debug(remove_ascii_format(log_msg_with_thread_id));
75 console->info(log_msg_with_thread_id);
77 syslog->info(remove_ascii_format(log_msg_with_thread_id));
81 console->warn(log_msg_with_thread_id);
83 syslog->warn(remove_ascii_format(log_msg_with_thread_id));
87 console->error(log_msg_with_thread_id);
89 syslog->error(remove_ascii_format(log_msg_with_thread_id));
93 console->critical(log_msg_with_thread_id);
95 syslog->critical(remove_ascii_format(log_msg_with_thread_id));
102 if (level ==
"DEBUG")
104 else if (level ==
"INFO")
106 else if (level ==
"WARNING")
108 else if (level ==
"ERROR")
110 else if (level ==
"CRIT")
112 throw std::runtime_error(
"Invalid log level: " + level);