Hello,
I try to create a formatter that can display logging messages (or just prints the severity level in different colors).
Given a format string like:
default_formatter = "%SeverityFormat% %Message%";
/// A custom formatter that handles the Severity formatting
class severity_formatter_factory :
public boost::log::formatter_factory<char>
{
public:
formatter_type create_formatter(boost::log::attribute_name const& name, args_map const& args)
{
namespace expr = boost::log::expressions;
return expr::stream <<
"|" << "\033[32m" << expr::attr("Severity") << "|";
}
};
and register with
bl::register_formatter_factory("SeverityFormat", boost::make_shared());
it basically works, i.e. the output is colored (all green) and the severity name is printed.
But how can I get the actual severity of the message that is about to be formatted inside the formatter? So I can act on
that and color warn messages red and info messages green?
What I found on the internets, e.g.
https://stackoverflow.com/questions/38309479/how-to-add-color-coding-to-boos...
http://www.boost.org/doc/libs/1_64_0/libs/log/doc/html/log/tutorial/formatte...
was using the sink->set_formatter method, which gives me, afaik, no possbility to configure using a format string.
But I'm open to any ideas...
Thanks,
Florian