i am trying to create a logger class that redirects std::cout
to a log file and OutputDebugStringA()
at the same time.
my code uses a library that uses std::cout
for debugging purposes, but i don't want to use the standard console because my code uses the windows subsystem and i want to output to visual studio's output window, but i want to log those messages that are redirected to the output window , to a simple text file , i know how to redirect cout to the output window, but i don't know how to print cout to a file and the output window at the same time.
struct Logger : public std::stringbuf{
Logger(){
std::cout.rdbuf(this);
}
~Logger(){
this->sync();
}
int sync(){
::OutputDebugStringA(str().c_str());
str(std::string());
return 0;
}
};