I'm using custom boost::log formatter for color coding the output log message, but I'm failing to find the proper way to add TimeStamp and ThreadID attributes to the log. When I'm using file logging I just write keywords::format = "[%TimeStamp%] [%ThreadID%] [%Severity%]: %Message%"
as logging::add_file_log
parameter. I want to have similar effect in the following custom formatter:
void coloring_formatter(const logging::record_view& record,
logging::formatting_ostream& stream)
{
auto severity = record[logging::trivial::severity];
assert(severity);
stream << "\e[1m";
switch (severity.get())
{
case logging::trivial::severity_level::trace:
stream << "\e[97m";
break;
case logging::trivial::severity_level::debug:
stream << "\e[34m";
break;
case logging::trivial::severity_level::info:
stream << "\e[32m";
break;
case logging::trivial::severity_level::warning:
stream << "\e[93m";
break;
case logging::trivial::severity_level::error:
stream << "\e[91m";
break;
case logging::trivial::severity_level::fatal:
stream << "\e[41m";
break;
}
stream // << output TimeStamp
// << output ThreadID
<< "[" << severity << "] "
<< record[logging::expressions::smessage]
<< "\e[0m";
}
format_date_time<boost::posix_time::ptime>
on that timestamp attribute? – Anaesthesiology