Boost logo

Boost Users :

Subject: [Boost-users] [boost::log] how to format a record message
From: Eric Prud'hommeaux (eric_at_[hidden])
Date: 2013-08-15 10:17:50


I have a project which has a handy stream filter in the formatter
which indents newlines in logged messages to some depth à la:
I/O [- 2 +] <loadedData>
                        {
                          <s> <p> <o> .
                          <s> <p> <o2> .
                        }
                        </loadedData>

(No, I'm not using an XML decorator above, though perhaps I should be.)
I've maintained this for several generations of boost::log, e.g.
#if (BOOST_VERSION > 104600) // could use (BOOST_LOG_COMPATIBILITY == "1.46") if cpp compared strings
                sink->set_formatter(&LineIndenter);
#else
                backend->set_formatter(&LineIndenter);
#endif

but now that boost::log's released (1000s of thanks!!!), I'd like to
switch to a channel_severity_filter. I had a custom formatter before
in order to fiddle with the rec.message:

        inline void LineIndenter (std::ostream& strm, logging::record const& rec)
        {
            std::stringstream ss;
            oprfxnstream prfxstr(ss.rdbuf(), depth, ' ');
            ... stuff with attrs
            prfxstr << rec.message();
            strm << ss.str();
        }

That member seems to be gone from logging::record and besides, it'd be
nicer to use something like:

    boost::log::add_console_log
        (std::clog,
         boost::log::keywords::filter = min_severity || severity >= critical,
         boost::log::keywords::format =
         (boost::log::expressions::stream
          << line_id
          << ": <" << severity
          << "> [" << channel << "] "
          << lineIndenter(boost::log::expressions::smessage)
          )
         );

I haven't figured out the signature for lineIndenter. I have the
impression that I'm implementing a decorator like
boost/log/expressions/formatters/c_decorator.hpp . So what's an easy
way to wrap the attached stream filter (or a subclass constructed with
some necessary constants) and pass it to a formatter?

-- 
-ericP



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net