0

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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This is actually not a bad idea, I will see if this is possible in my setup.
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.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.