0

Is it possible to access the underlying stream instance used by BOOST_LOG_TRIVIAL?

I'm trying to have BOOST unit test framework write output using BOOST_LOG_TRIVIAL (which I have configured to write in a file and std::clog)

auto& log_stream = ??? // BOOST_LOG_TRIVIAL stream instance boost::unit_test::unit_test_log.instance().set_stream(log_stream);

Florin Neamtu
  • 25
  • 1
  • 6

1 Answers1

1

Is it possible to access the underlying stream instance used by BOOST_LOG_TRIVIAL?

No, it's not. Internally, the default sink in Boost.Log, which is used by BOOST_LOG_TRIVIAL unless you configured your own sink, does not even use a stream.

I think, the best way to integrate Boost.Test with Boost.Log is to implement your own stream buffer (a class derived from std::streambuf). The buffer would have to convert the output from Boost.Test into separate log records (e.g. by splitting it at newline characters) and pass the records to Boost.Log via BOOST_LOG_TRIVIAL or other means. You can then create a std::ostream object referring to your stream buffer and pass it to Boost.Test into set_stream.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27
  • Thanks Andrey, implementing my own proxy was my first thought, I just hoped that this might be a common case, already with a solution. It seems not. From what I've seen briefly in the documentation using sinks might be a solution as well, and wouldn't need my own proxies. Not sure if I have time to investigate more the sinks. – Florin Neamtu Nov 07 '16 at 10:18