I have changed the logging and printout of messages in one of my application by the spdlog library. Everything works within the code that I control. The issue that I faced is that I do not manage to redirect the print out and other error messages from a 3rd party library.
In the library, std::cout and std::cerr are redirected to an intermediate std::ostream named errorOut or printOut, which are defined globally in the library as extern std::ostream printOut;
and implemented as std::ostream library::printOut(std::cout.rdbuf());
I have tried to change the redirected stream to an std::ostringstream : std::ostringstream ss; library::printOut.rdbuf(ss.rdbuf());
. Then, I used it for a sink of spdlog with auto sink2 = std::make_shared<spdlog::sinks::ostream_sink_mt> (ss);
and combined it in combined logger.
However doing so, the error messages from the library are not print out in cout/cerr as normally.
Therefore, how to redirect / capture a defined ostream from a library to spdlog without modifying those libraries ?
Thanks for your help and inputs.