I have a requirement, I need to use printf
and cout
to display the data into console and file
as well.
For printf
I have
If i guess correctly you want to log everything that goes to the output also into a file.
What you want is an observer pattern.
Replace all direct logging in your code with calls to a new relay. The logging relay sends your messages to the observers. One of your observers loggs the message to the screen. The other one loggs to the file. Avoid making your relay a singleton if possible.
This suggestion only works if you can edit all of your source files.