0

How can I use BOOST_LOG_TRIVIAL macro to log anything to both stdout / stderr and file?

If I do

  boost::log::add_file_log
  (
    boost::log::keywords::file_name =
      "logs/%Y-%m-%d_%H-%M-%S.%N.log",
    boost::log::keywords::rotation_size = 10 * 1024 * 1024,
    boost::log::keywords::time_based_rotation =
      boost::log::sinks::file::rotation_at_time_point(0, 0, 0),
    boost::log::keywords::format = "[%TimeStamp%]: %Message%"
  );
  boost::log::add_common_attributes();

It won't log anything to stdout / stderr, only file.

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242

1 Answers1

2

while learning about Boost Log I came across an answer to this question:

Changing or adding a stream for the default core sink replaces the default stream (stdout). To add it back you can use the boost::log::add_console_log(std::cout) with the associated format specifiers. Just add both std::cout and std::clog for stdout and stderr respectively.

This method can be found in this header file: boost/log/utility/setup/console.hpp

John
  • 1,709
  • 1
  • 24
  • 27