Fix logging fatal exceptions to cerr, and log them to openmw.log

deque
scrawl 11 years ago
parent 4f742fd468
commit 54d8606b78

@ -294,9 +294,19 @@ private:
int main(int argc, char**argv) int main(int argc, char**argv)
{ {
// Some objects used to redirect cout and cerr
// Scope must be here, so this still works inside the catch block for logging exceptions
std::streambuf* cout_rdbuf = std::cout.rdbuf (); std::streambuf* cout_rdbuf = std::cout.rdbuf ();
std::streambuf* cerr_rdbuf = std::cerr.rdbuf (); std::streambuf* cerr_rdbuf = std::cerr.rdbuf ();
boost::iostreams::stream_buffer<Tee> coutsb;
boost::iostreams::stream_buffer<Tee> cerrsb;
std::ostream oldcout(cout_rdbuf);
std::ostream oldcerr(cerr_rdbuf);
boost::filesystem::ofstream logfile;
int ret = 0; int ret = 0;
try try
{ {
@ -310,20 +320,16 @@ int main(int argc, char**argv)
std::cerr.rdbuf (&sb); std::cerr.rdbuf (&sb);
#else #else
// Redirect cout and cerr to openmw.log // Redirect cout and cerr to openmw.log
boost::filesystem::ofstream logfile (boost::filesystem::path( logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/openmw.log"));
cfgMgr.getLogPath() / "/openmw.log"));
boost::iostreams::stream_buffer<Tee> coutsb;
std::ostream oldcout(cout_rdbuf);
coutsb.open (Tee(logfile, oldcout)); coutsb.open (Tee(logfile, oldcout));
std::cout.rdbuf (&coutsb);
boost::iostreams::stream_buffer<Tee> cerrsb;
std::ostream oldcerr(cerr_rdbuf);
cerrsb.open (Tee(logfile, oldcerr)); cerrsb.open (Tee(logfile, oldcerr));
std::cout.rdbuf (&coutsb);
std::cerr.rdbuf (&cerrsb); std::cerr.rdbuf (&cerrsb);
#endif #endif
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// Unix crash catcher // Unix crash catcher
if ((argc == 2 && strcmp(argv[1], "--cc-handle-crash") == 0) || !is_debugger_attached()) if ((argc == 2 && strcmp(argv[1], "--cc-handle-crash") == 0) || !is_debugger_attached())

Loading…
Cancel
Save