In my process I have LOG macros, these macros output the text to std::cout and to a file. My program is linked with 3rd party libraries which output their text directly to std::cout. I have no control over the code in the external libraries and API they expose does not have an option to redirect the output to a file. Is there a way I can still control the output and redirect it to std::cout and to a file?
Asked
Active
Viewed 411 times
1 Answers
1
I am not 100% sure about shared libraries, but in principle this should work the same. Just redirect stdout and stderr to a new stream buffer.

msmith81886
- 2,286
- 2
- 20
- 27
-
This is actually not a bad idea, I will see if this is possible in my setup. – e271p314 Mar 26 '18 at 04:35
-
The problem is that I print to std::cout with colors which includes escaped characters so the same message is printed to file without color characters, I can not simply forward everything from std::cout to a file. But I still like your idea, I will see if I can use it some other way. – e271p314 Mar 26 '18 at 05:02
-
Doesn't redirecting std::cout to a file will cause my output not to be written to screen? I want the output on the screen stay the same, just be able to add logs from external libraries to my log file – e271p314 Mar 26 '18 at 05:09