11

I've used boost::log successfully to log to stdout (using the TRIVIAL macros) or to log to a file (basically following the steps in the tutorial).

How would we configure to log to a file and stdout simultaneously?

This is a common use case in our setup when we want to have both, a log file and also all the output that goes to the log on the console.

Any input appreciated!

Patrizio Bertoni
  • 2,582
  • 31
  • 43
cacau
  • 3,606
  • 3
  • 21
  • 42
  • have you tried reading [this documentation](http://boost-log.sourceforge.net/libs/log/doc/html/log/tutorial/sinks.html)? It says `You can register more than one sink. Each sink will receive and process log records as you emit them independently from others. ` – nurettin Jan 27 '14 at 12:14
  • @nurettin Yep, but how do you register sinks for output to stdout? Couldn't find that (yet..) – cacau Jan 27 '14 at 12:30
  • 2
    add_stream( boost::shared_ptr(&std::cout, empty_deleter() ) ); // ? – nurettin Jan 27 '14 at 13:47

1 Answers1

23

As per the docs you can simply use the add_console_log() convenience function like so:

#include <boost/log/utility/setup/console.hpp>

logging::add_console_log(std::cout, boost::log::keywords::format = ">> %Message%");

Of course you can always dig into the sink configuration manually as indicated by some of the comments.

Jay
  • 6,572
  • 3
  • 37
  • 65