6

I have a library, which sends messages to the console using std::cout and std::cerr.

I know, I can redirect that in my GUI Application. But, what I wonder is, if there is a way to detect if cout or cerr was used before the message is actually flushed?

Background: I would like to be able to change the text color and put a string like "Error: " in front of the message, if the text comes from cerr.

E.g. if there was a line

cerr << "File not found" << endl;

in the library, is there a kind of callback or event that I can use to make sure that I can execute a

cerr << "Error: ";

from my side before the original error message without touching the original library?

Note that redirecting to a string as in the question redirect stdout/stderr to a string would require me to know when the library creates an output and do something with that string. Instead I am looking for a sort of automatic mechanism.

Community
  • 1
  • 1
Kağan Kayal
  • 2,303
  • 1
  • 19
  • 30
  • 4
    _"I have a library, which sends messages to the console using std::cout and std::cerr."_ I'm sorry to hear that :( – Lightness Races in Orbit Jan 12 '17 at 15:36
  • 3
    http://stackoverflow.com/a/22119115/3313064 actually shows you how to do this. Replace `getTime()` with `"Error: "` and you are done. But know that the library you are using has a bad design error if it does not allow you to customise logging. – Christian Hackl Jan 12 '17 at 15:41
  • @Christian Thanks, your link to the [question](http://stackoverflow.com/questions/22118713/add-time-stamp-with-stdcout/22119115#22119115) solved my problem. The accepted answer there worked. – Kağan Kayal Jan 12 '17 at 17:26

0 Answers0