Save the last three stdout.log files (which is useful in diagnosing
crashes caused by e.g. a problem in a previous run).
This commit is contained in:
@@ -996,12 +996,36 @@ std::string FileManager::checkAndCreateLinuxDir(const char *env_name,
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Redirects output to go into files in the user's config directory
|
||||
* instead of to the console.
|
||||
* instead of to the console. It keeps backup copies of previous stdout files
|
||||
* (3 atm), which can help to diagnose problems caused by a previous crash.
|
||||
*/
|
||||
void FileManager::redirectOutput()
|
||||
{
|
||||
//Enable logging of stdout and stderr to logfile
|
||||
// Do a simple log rotate: stdout.log.2 becomes stdout.log.3 etc
|
||||
const int NUM_BACKUPS=3;
|
||||
std::string logoutfile = getUserConfigFile("stdout.log");
|
||||
for(int i=NUM_BACKUPS; i>1; i--)
|
||||
{
|
||||
std::ostringstream out_old;
|
||||
out_old << logoutfile << "." << i;
|
||||
removeFile(out_old.str());
|
||||
std::ostringstream out_new;
|
||||
out_new << logoutfile << "." << i-1;
|
||||
if(fileExists(out_new.str()))
|
||||
{
|
||||
rename(out_new.str().c_str(), out_old.str().c_str());
|
||||
}
|
||||
} // for i in NUM_BACKUPS
|
||||
|
||||
if(fileExists(logoutfile))
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << logoutfile<<".1";
|
||||
// No good place to log error messages when log is not yet initialised
|
||||
rename(logoutfile.c_str(), out.str().c_str());
|
||||
}
|
||||
|
||||
//Enable logging of stdout and stderr to logfile
|
||||
Log::verbose("main", "Error messages and other text output will "
|
||||
"be logged to %s.", logoutfile.c_str());
|
||||
Log::openOutputFiles(logoutfile);
|
||||
|
||||
Reference in New Issue
Block a user