I need a logger for C++. And I found this post Small logger class, which led me to this simple logger http://www.drdobbs.com/cpp/201804215.
It mainly uses the following method to wirte to log file.
FILE* pFile = fopen("application.log", "a");
std::ostringstream os;
os<<"I am a log line."<<std::endl;
fprintf(pFile, "%s", os.str().c_str());
fflush(pFile);
But it doesn't work as I expected. I assume, with the log file open in notepad, each new log line would be showing immediately after fprintf and fflush. But it turned out that I have to close and reopen the file with notepad to see the update.
So is there a way to write log file in C++ that allows reading in real time, which makes the log file resemble win32 console or VS output window? I miss the days when I can dump everything to console.log in Javascript. :)
Thanks.