Log: Coloring logging output

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Log: Coloring logging output

Boost - Users mailing list

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>
  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<boost::log::trivial::severity_level >("Severity") << "|";

and register with

bl::register_formatter_factory("SeverityFormat", boost::make_shared<severity_formatter_factory>());

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.


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...


Boost-users mailing list
[hidden email]