Add option to Preferences to flush file loggers when a signal is triggered

This commit is contained in:
Magne Sjaastad
2024-01-31 14:41:57 +01:00
parent 710b91d161
commit 06766b3650
6 changed files with 75 additions and 0 deletions

View File

@@ -17,6 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RiaMainTools.h"
#include "RiaFileLogger.h"
#include "RiaLogging.h"
#include "RiaRegressionTestRunner.h"
#include "RiaSocketCommand.h"
@@ -25,6 +27,32 @@
#include "cafPdmDefaultObjectFactory.h"
#include "cafPdmUiFieldEditorHandle.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void manageSegFailure( int signalCode )
{
// Executing function here is not safe, but works as expected on Windows. Behavior on Linux is undefined, but will
// work in some cases.
// https://github.com/gabime/spdlog/issues/1607
auto loggers = RiaLogging::loggerInstances();
QString str = QString( "Segmentation fault. Signal code: %1" ).arg( signalCode );
for ( auto logger : loggers )
{
if ( auto fileLogger = dynamic_cast<RiaFileLogger*>( logger ) )
{
fileLogger->error( str.toStdString().data() );
fileLogger->flush();
}
}
exit( 1 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------