Hi, I am writing a program which is using taglib to read audio tags. When calling the taglib dll, sometimes a std::cerr message is generated. I want to catch these messages and save them in a log. I have tried
std::ofstream ostr("log.txt"); //or std::ostringstream ostr;
std::streambuf * old_buffer = std::cerr.rdbuf();
std::cerr.rdbuf(ostr.rdbuf());

which works well for std::cerr messages made from within my program, but the std::cerr messages from the dll are not captured. Any clues?

When you run your program from the command line, redirect stderr to a file: $ myprogram 2> log.txt

The program is a GUI :-) Without a console

Open the stderr log file for writing (with CreateFile ).
Call SetStdHandle( STD_ERROR_HANDLE, log_file_handle ) ; to redirect stderr for the process to the log file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.