From b7034dad4e5bed426808c7a10e4275ecd5620888 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 20 Feb 2026 16:58:49 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8adding=20diagnostic-info-level=20c?= =?UTF-8?q?ommand=20line=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/logger/ErrorHandling.cpp | 56 ++++++++++++++++--- .../common/logger/ErrorHandling.hpp | 45 +++++++++++++-- .../common/logger/GeosExceptions.cpp | 5 +- .../unitTests/testErrorHandling.cpp | 4 +- .../dataRepositoryTests/testGroupPath.cpp | 2 +- .../mainInterface/initialization.cpp | 12 ++++ 6 files changed, 109 insertions(+), 15 deletions(-) diff --git a/src/coreComponents/common/logger/ErrorHandling.cpp b/src/coreComponents/common/logger/ErrorHandling.cpp index 6881e11259a..5dc464e776a 100644 --- a/src/coreComponents/common/logger/ErrorHandling.cpp +++ b/src/coreComponents/common/logger/ErrorHandling.cpp @@ -45,6 +45,11 @@ ErrorLogger g_errorLogger{}; ErrorLogger & ErrorLogger::global() { return g_errorLogger; } +ErrorLogger::ErrorLogger() +{ + setDiagnosticInfoLevel( DiagnosticInfoLevel::Basic ); +} + std::string ErrorContext::attributeToString( ErrorContext::Attribute attribute ) { switch( attribute ) @@ -277,7 +282,28 @@ void ErrorLogger::createFile() } } -std::string ErrorLogger::toString( MsgType const type ) +void ErrorLogger::setDiagnosticInfoLevel( DiagnosticInfoLevel const level ) +{ + m_msgTypeSourceInfoEnabled.fill( false ); + switch( level ) + { + case DiagnosticInfoLevel::Basic: + // no diag info + break; + case DiagnosticInfoLevel::ErrorSources: + m_msgTypeSourceInfoEnabled[integer( MsgType::Error )] = true; + m_msgTypeSourceInfoEnabled[integer( MsgType::ExternalError )] = true; + m_msgTypeSourceInfoEnabled[integer( MsgType::Exception )] = true; + m_msgTypeSourceInfoEnabled[integer( MsgType::Undefined )] = true; + [[fallthrough]]; + case DiagnosticInfoLevel::WarningSources: + m_msgTypeSourceInfoEnabled[integer( MsgType::Warning )] = true; + break; + } +} + + +std::string ErrorLogger::typeToString( MsgType const type ) { switch( type ) { @@ -289,12 +315,26 @@ std::string ErrorLogger::toString( MsgType const type ) } } -void ErrorLogger::formatMsgForLog( DiagnosticMsg const & errMsg, std::ostream & os ) +bool ErrorLogger::isSourceInfoEnabled( MsgType const type ) const +{ + switch( type ) + { + case MsgType::Error: return m_msgTypeSourceInfoEnabled[integer( MsgType::Error )]; + case MsgType::Warning: return m_msgTypeSourceInfoEnabled[integer( MsgType::Warning )]; + case MsgType::Exception: return m_msgTypeSourceInfoEnabled[integer( MsgType::Exception )]; + case MsgType::ExternalError: return m_msgTypeSourceInfoEnabled[integer( MsgType::ExternalError )]; + default: return m_msgTypeSourceInfoEnabled[integer( MsgType::Undefined )]; + } +} + +void ErrorLogger::formatMsgForLog( DiagnosticMsg const & errMsg, + std::ostream & os, + bool enableSourceInfo ) { static constexpr string_view PREFIX = "***** "; // --- HEADER --- - os << PREFIX << ErrorLogger::toString( errMsg.m_type ) << "\n"; - if( !errMsg.m_file.empty()) + os << PREFIX << typeToString( errMsg.m_type ) << "\n"; + if( enableSourceInfo && !errMsg.m_file.empty() ) { os << PREFIX<< "LOCATION: " << errMsg.m_file; if( errMsg.m_line > 0 ) @@ -332,7 +372,7 @@ void ErrorLogger::formatMsgForLog( DiagnosticMsg const & errMsg, std::ostream & } } // --- STACKTRACE --- - if( !errMsg.m_sourceCallStack.empty() ) + if( enableSourceInfo && !errMsg.m_sourceCallStack.empty() ) { os << "\n***** StackTrace of "<< errMsg.m_sourceCallStack.size() << " frames\n"; for( size_t i = 0; i < errMsg.m_sourceCallStack.size(); i++ ) @@ -353,7 +393,9 @@ void ErrorLogger::formatMsgForLog( DiagnosticMsg const & errMsg, std::ostream & void ErrorLogger::writeToLogStream( DiagnosticMsg & errMsg ) { std::lock_guard< std::mutex > guard( m_errorHandlerAsciiMutex ); - formatMsgForLog( errMsg, m_stream ); + formatMsgForLog( errMsg, + m_stream, + isSourceInfoEnabled( errMsg.m_type ) ); m_stream.flush(); } @@ -364,7 +406,7 @@ void ErrorLogger::writeToYamlStream( DiagnosticMsg & errMsg ) if( yamlFile.is_open() ) { // General errors info (type, rank on which the error occured) - yamlFile << g_level1Start << "type: " << ErrorLogger::toString( errMsg.m_type ) << "\n"; + yamlFile << g_level1Start << "type: " << typeToString( errMsg.m_type ) << "\n"; yamlFile << g_level1Next << "rank: " << stringutilities::join( errMsg.m_ranksInfo, "," ); yamlFile << "\n"; diff --git a/src/coreComponents/common/logger/ErrorHandling.hpp b/src/coreComponents/common/logger/ErrorHandling.hpp index 38df2a2566c..36fed82ec06 100644 --- a/src/coreComponents/common/logger/ErrorHandling.hpp +++ b/src/coreComponents/common/logger/ErrorHandling.hpp @@ -23,6 +23,7 @@ #include "common/DataTypes.hpp" #include "common/format/Format.hpp" #include "common/format/StringUtilities.hpp" +#include #include namespace geos @@ -111,13 +112,28 @@ struct ErrorContext * @enum MsgType * Enum listing the different types of possible diagnostics */ -enum class MsgType +enum class MsgType : integer { + Undefined, Error, ExternalError, Warning, Exception, - Undefined + Count // internal use, keep at last +}; + +/** + * @enum MsgType + * Enum listing the different types of possible diagnostic information levels + */ +enum class DiagnosticInfoLevel : integer +{ + /// basic information (default) + Basic = 1, + /// errors source-code information + ErrorSources= 2, + /// warnings & errors source-code information + WarningSources = 3, }; /** @@ -295,6 +311,8 @@ class ErrorLogger */ GEOS_HOST static ErrorLogger & global(); + ErrorLogger(); + /** * @brief Create the YAML file or overwrite the contents if a YAML file of the same name already exists * And write its header when the command line option is enabled @@ -322,6 +340,14 @@ class ErrorLogger void setOutputFilename( std::string_view filename ) { m_filename = filename; } + /** + * @brief Set the diagnostic messages information level. The higher, the more verbose and + * developper-oriented the messages will be. + * @param level the desired information level. If level is not an DiagnosticInfoLevel enum label, + * the behaviour of DiagnosticInfoLevel::Basic. + */ + void setDiagnosticInfoLevel( DiagnosticInfoLevel level ); + /** * @return The file name of the output error file */ @@ -333,7 +359,13 @@ class ErrorLogger * @param type the message type label * @return the string representation of the message type */ - static std::string toString( MsgType type ); + static std::string typeToString( MsgType type ); + + /** + * @param type the message type label + * @return true if the message type source information output is enabled + */ + bool isSourceInfoEnabled( MsgType type ) const; /** * @return Return the const general log stream @@ -384,8 +416,11 @@ class ErrorLogger * @brief Format all information in ErrorMsg and write it to the specified output stream * @param errMsg The struct containing the error/warning object * @param os The output stream + * @param enableSourceInfo if true, information on source code is included in the message */ - static void formatMsgForLog( DiagnosticMsg const & errMsg, std::ostream & os ); + static void formatMsgForLog( DiagnosticMsg const & errMsg, + std::ostream & os, + bool enableSourceInfo ); /** * @brief Write the ErrorMsg into the log stream output stream @@ -407,6 +442,8 @@ class ErrorLogger std::mutex m_errorHandlerAsciiMutex; /// Avoid concurrent access between threads for yaml outputs std::mutex m_errorHandlerYamlMutex; + /// Indicated if the source file information output is enabled for a given message type + stdArray< bool, size_t( MsgType::Count ) > m_msgTypeSourceInfoEnabled; /** * @brief Write all the information retrieved about the error/warning message into the YAML stream diff --git a/src/coreComponents/common/logger/GeosExceptions.cpp b/src/coreComponents/common/logger/GeosExceptions.cpp index 4aa13914337..4c1abe33aa0 100644 --- a/src/coreComponents/common/logger/GeosExceptions.cpp +++ b/src/coreComponents/common/logger/GeosExceptions.cpp @@ -19,6 +19,7 @@ #include "common/logger/GeosExceptions.hpp" +#include "common/logger/ErrorHandling.hpp" namespace geos { @@ -30,7 +31,9 @@ void Exception::prepareWhat( DiagnosticMsg & msg ) noexcept m_formattingOSS.str( "" ); m_formattingOSS.clear(); - ErrorLogger::formatMsgForLog( msg, m_formattingOSS ); + ErrorLogger::formatMsgForLog( msg, + m_formattingOSS, + ErrorLogger::global().isSourceInfoEnabled( msg.m_type ) ); m_cachedWhat = m_formattingOSS.bad() ? "Exception formatting error!" : m_formattingOSS.str(); } diff --git a/src/coreComponents/dataRepository/unitTests/testErrorHandling.cpp b/src/coreComponents/dataRepository/unitTests/testErrorHandling.cpp index 33e95b745d4..ee7c274db08 100644 --- a/src/coreComponents/dataRepository/unitTests/testErrorHandling.cpp +++ b/src/coreComponents/dataRepository/unitTests/testErrorHandling.cpp @@ -321,7 +321,7 @@ TEST( ErrorHandling, testLogFileExceptionOutput ) additionalContext.toString(), testErrorLogger.getCurrentExceptionMsg().m_sourceCallStack ); std::ostringstream oss; - ErrorLogger::formatMsgForLog( testErrorLogger.getCurrentExceptionMsg(), oss ); + ErrorLogger::formatMsgForLog( testErrorLogger.getCurrentExceptionMsg(), oss, true ); GEOS_ERROR_IF_EQ_MSG( oss.str().find( streamExpected ), string::npos, "The error message was not containing the expected sequence.\n" << "The error message was not containing the expected sequence.\n" << @@ -347,7 +347,7 @@ TEST( ErrorHandling, testStdException ) .addCallStackInfo( LvArray::system::stackTrace( true ) ); std::ostringstream oss; - ErrorLogger::formatMsgForLog( testErrorLogger.getCurrentExceptionMsg(), oss ); + ErrorLogger::formatMsgForLog( testErrorLogger.getCurrentExceptionMsg(), oss, true ); string const streamExpected = GEOS_FMT( "***** Exception\n" "***** Rank 0\n" diff --git a/src/coreComponents/integrationTests/dataRepositoryTests/testGroupPath.cpp b/src/coreComponents/integrationTests/dataRepositoryTests/testGroupPath.cpp index 37724a42378..e047c9466ee 100644 --- a/src/coreComponents/integrationTests/dataRepositoryTests/testGroupPath.cpp +++ b/src/coreComponents/integrationTests/dataRepositoryTests/testGroupPath.cpp @@ -114,7 +114,7 @@ TEST( testGroupPath, testGlobalPaths ) "The children of Mesh are: { mesh1 }"; // checks if the exception contains the expected message std::ostringstream stream; - geos::ErrorLogger::formatMsgForLog( ErrorLogger::global().getCurrentExceptionMsg(), stream ); + geos::ErrorLogger::formatMsgForLog( ErrorLogger::global().getCurrentExceptionMsg(), stream, false ); GEOS_ERROR_IF_EQ_MSG( string( e.what() ).find( expectedMsg ), string::npos, "The error message was not containing the expected sequence.\n" << " Error message :\n" << e.what() << diff --git a/src/coreComponents/mainInterface/initialization.cpp b/src/coreComponents/mainInterface/initialization.cpp index 39367cbb263..99083f6c27e 100644 --- a/src/coreComponents/mainInterface/initialization.cpp +++ b/src/coreComponents/mainInterface/initialization.cpp @@ -14,6 +14,7 @@ */ #include "initialization.hpp" +#include "common/logger/ErrorHandling.hpp" #include "version.hpp" #include "common/DataTypes.hpp" @@ -97,6 +98,7 @@ std::unique_ptr< CommandLineOptions > parseCommandLineOptions( int argc, char * ZPAR, SCHEMA, VALIDATE_INPUT, + DIAGNOSTIC_INFO_LEVEL, NONBLOCKING_MPI, SUPPRESS_PINNED, PROBLEMNAME, @@ -121,6 +123,10 @@ std::unique_ptr< CommandLineOptions > parseCommandLineOptions( int argc, char * { ZPAR, 0, "z", "zpartitions", Arg::numeric, "\t-z, --z-partitions, \t Number of partitions in the z-direction" }, { SCHEMA, 0, "s", "schema", Arg::nonEmpty, "\t-s, --schema, \t Name of the output schema" }, { VALIDATE_INPUT, 0, "v", "validate-input", Arg::None, "\t-v, --validate-input, \t Only do the loading phase, and not actual simulation. Useful to validate 'input'." }, + { DIAGNOSTIC_INFO_LEVEL, 0, "d", "diagnostic-info-level", Arg::numeric, "\t-d, --diagnostic-info-level, \t Diagnostic message information level:\n" + "\t \t 1 = basic information (default),\n" + "\t \t 2 = errors source-code information,\n" + "\t \t 3 = warnings & errors source-code information." }, { NONBLOCKING_MPI, 0, "b", "use-nonblocking", Arg::None, "\t-b, --use-nonblocking, \t Use non-blocking MPI communication" }, { PROBLEMNAME, 0, "n", "name", Arg::nonEmpty, "\t-n, --name, \t Name of the problem, used for output" }, { SUPPRESS_PINNED, 0, "s", "suppress-pinned", Arg::None, "\t-s, --suppress-pinned, \t Suppress usage of pinned memory for MPI communication buffers" }, @@ -222,6 +228,12 @@ std::unique_ptr< CommandLineOptions > parseCommandLineOptions( int argc, char * commandLineOptions->onlyValidateInput = true; } break; + case DIAGNOSTIC_INFO_LEVEL: + { + DiagnosticInfoLevel infoLevel = DiagnosticInfoLevel( std::stoi( opt.arg ) ); + ErrorLogger::global().setDiagnosticInfoLevel( infoLevel ); + } + break; case PROBLEMNAME: { commandLineOptions->problemName = opt.arg; From ea26cee6725925857b1136401d008ee481c460c0 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Fri, 20 Feb 2026 17:59:41 +0100 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=90=9Bmore=20classic=20switch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/logger/ErrorHandling.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/common/logger/ErrorHandling.cpp b/src/coreComponents/common/logger/ErrorHandling.cpp index 5dc464e776a..4a705161c10 100644 --- a/src/coreComponents/common/logger/ErrorHandling.cpp +++ b/src/coreComponents/common/logger/ErrorHandling.cpp @@ -18,6 +18,7 @@ */ #include "ErrorHandling.hpp" +#include "LvArray/src/system.hpp" #include "common/DataTypes.hpp" #include "common/logger/Logger.hpp" #include "common/format/StringUtilities.hpp" @@ -284,20 +285,17 @@ void ErrorLogger::createFile() void ErrorLogger::setDiagnosticInfoLevel( DiagnosticInfoLevel const level ) { - m_msgTypeSourceInfoEnabled.fill( false ); switch( level ) { case DiagnosticInfoLevel::Basic: - // no diag info + m_msgTypeSourceInfoEnabled.fill( false ); break; case DiagnosticInfoLevel::ErrorSources: - m_msgTypeSourceInfoEnabled[integer( MsgType::Error )] = true; - m_msgTypeSourceInfoEnabled[integer( MsgType::ExternalError )] = true; - m_msgTypeSourceInfoEnabled[integer( MsgType::Exception )] = true; - m_msgTypeSourceInfoEnabled[integer( MsgType::Undefined )] = true; - [[fallthrough]]; + m_msgTypeSourceInfoEnabled.fill( true ); + m_msgTypeSourceInfoEnabled[integer( MsgType::Warning )] = false; + break; case DiagnosticInfoLevel::WarningSources: - m_msgTypeSourceInfoEnabled[integer( MsgType::Warning )] = true; + m_msgTypeSourceInfoEnabled.fill( true ); break; } } From 5380a1d022b9abab3f0108f48f57c1446ad6a055 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 23 Feb 2026 10:31:35 +0100 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=90=9Bbetter=20managment=20of=20wrong?= =?UTF-8?q?=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/logger/ErrorHandling.cpp | 4 ++++ src/coreComponents/common/logger/ErrorHandling.hpp | 6 +++--- src/coreComponents/mainInterface/initialization.cpp | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/coreComponents/common/logger/ErrorHandling.cpp b/src/coreComponents/common/logger/ErrorHandling.cpp index 4a705161c10..f68de5aca15 100644 --- a/src/coreComponents/common/logger/ErrorHandling.cpp +++ b/src/coreComponents/common/logger/ErrorHandling.cpp @@ -297,6 +297,10 @@ void ErrorLogger::setDiagnosticInfoLevel( DiagnosticInfoLevel const level ) case DiagnosticInfoLevel::WarningSources: m_msgTypeSourceInfoEnabled.fill( true ); break; + default: + // if option has a wrong value, we output every details for any messages + m_msgTypeSourceInfoEnabled.fill( true ); + break; } } diff --git a/src/coreComponents/common/logger/ErrorHandling.hpp b/src/coreComponents/common/logger/ErrorHandling.hpp index 36fed82ec06..29cf96591a8 100644 --- a/src/coreComponents/common/logger/ErrorHandling.hpp +++ b/src/coreComponents/common/logger/ErrorHandling.hpp @@ -129,11 +129,11 @@ enum class MsgType : integer enum class DiagnosticInfoLevel : integer { /// basic information (default) - Basic = 1, + Basic = 0, /// errors source-code information - ErrorSources= 2, + ErrorSources= 1, /// warnings & errors source-code information - WarningSources = 3, + WarningSources = 2, }; /** diff --git a/src/coreComponents/mainInterface/initialization.cpp b/src/coreComponents/mainInterface/initialization.cpp index 99083f6c27e..03bae3884fb 100644 --- a/src/coreComponents/mainInterface/initialization.cpp +++ b/src/coreComponents/mainInterface/initialization.cpp @@ -124,9 +124,9 @@ std::unique_ptr< CommandLineOptions > parseCommandLineOptions( int argc, char * { SCHEMA, 0, "s", "schema", Arg::nonEmpty, "\t-s, --schema, \t Name of the output schema" }, { VALIDATE_INPUT, 0, "v", "validate-input", Arg::None, "\t-v, --validate-input, \t Only do the loading phase, and not actual simulation. Useful to validate 'input'." }, { DIAGNOSTIC_INFO_LEVEL, 0, "d", "diagnostic-info-level", Arg::numeric, "\t-d, --diagnostic-info-level, \t Diagnostic message information level:\n" - "\t \t 1 = basic information (default),\n" - "\t \t 2 = errors source-code information,\n" - "\t \t 3 = warnings & errors source-code information." }, + "\t \t 0 = basic information (default),\n" + "\t \t 1 = errors source-code information,\n" + "\t \t 2 = warnings & errors source-code information." }, { NONBLOCKING_MPI, 0, "b", "use-nonblocking", Arg::None, "\t-b, --use-nonblocking, \t Use non-blocking MPI communication" }, { PROBLEMNAME, 0, "n", "name", Arg::nonEmpty, "\t-n, --name, \t Name of the problem, used for output" }, { SUPPRESS_PINNED, 0, "s", "suppress-pinned", Arg::None, "\t-s, --suppress-pinned, \t Suppress usage of pinned memory for MPI communication buffers" }, From 9e5c55dbc7e4dd3b70816a56738fe8151d56be77 Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 23 Feb 2026 14:06:04 +0100 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20useless=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/logger/ErrorHandling.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/logger/ErrorHandling.hpp b/src/coreComponents/common/logger/ErrorHandling.hpp index 29cf96591a8..f4792381a6a 100644 --- a/src/coreComponents/common/logger/ErrorHandling.hpp +++ b/src/coreComponents/common/logger/ErrorHandling.hpp @@ -23,7 +23,7 @@ #include "common/DataTypes.hpp" #include "common/format/Format.hpp" #include "common/format/StringUtilities.hpp" -#include + #include namespace geos From ad944343000cc703470e97d6392dacd7e0b0d11a Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 23 Feb 2026 15:44:59 +0100 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9A=B0=EF=B8=8Fuseless=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/logger/GeosExceptions.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreComponents/common/logger/GeosExceptions.cpp b/src/coreComponents/common/logger/GeosExceptions.cpp index 4c1abe33aa0..3746d41e703 100644 --- a/src/coreComponents/common/logger/GeosExceptions.cpp +++ b/src/coreComponents/common/logger/GeosExceptions.cpp @@ -19,7 +19,6 @@ #include "common/logger/GeosExceptions.hpp" -#include "common/logger/ErrorHandling.hpp" namespace geos { From 7507c27739f4633d531a91601b1531d9eba99fcc Mon Sep 17 00:00:00 2001 From: MelReyCG Date: Mon, 23 Feb 2026 15:45:38 +0100 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=93=9Ddocumentation=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/common/logger/ErrorHandling.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/logger/ErrorHandling.hpp b/src/coreComponents/common/logger/ErrorHandling.hpp index f4792381a6a..2c95b108971 100644 --- a/src/coreComponents/common/logger/ErrorHandling.hpp +++ b/src/coreComponents/common/logger/ErrorHandling.hpp @@ -123,7 +123,7 @@ enum class MsgType : integer }; /** - * @enum MsgType + * @enum DiagnosticInfoLevel * Enum listing the different types of possible diagnostic information levels */ enum class DiagnosticInfoLevel : integer