To redirect the output to the Boost logger via ostream, I needed to create a receiver using the Boost Iostreams library. Thanks @sehe for the tip!
++ 11 :
#include <iosfwd>
#include <boost/iostreams/categories.hpp>
class Logger_Sink
{
public:
typedef char char_type;
typedef boost::iostreams::sink_tag category;
Logger_Sink() = default;
virtual
~Logger_Sink() = default;
virtual
std::streamsize
write(
char_type const * s,
std::streamsize n) = 0;
};
class cout_Sink: public Logger_Sink
{
public:
std::streamsize
write(
char_type const * s,
std::streamsize n)
{
BOOST_LOG_TRIVIAL(info) << std::string(s, n);
return n;
}
};
ostream:
#include <iostream>
#include <boost/iostreams/stream.hpp>
namespace io = boost::iostreams;
io::stream_buffer<cout_Sink> cout_buf((cout_Sink()));
std::ostream mycout(&cout_buf);