From 9ee59769468c8a674894b7ca86ed4f1cc1ba8511 Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 26 Apr 2024 13:39:47 +0200 Subject: [PATCH] Always clear log consumers before exiting Signed-off-by: tempate --- fastddsspy_tool/src/cpp/main.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fastddsspy_tool/src/cpp/main.cpp b/fastddsspy_tool/src/cpp/main.cpp index 13054971..3bc886a8 100644 --- a/fastddsspy_tool/src/cpp/main.cpp +++ b/fastddsspy_tool/src/cpp/main.cpp @@ -47,6 +47,10 @@ #include "user_interface/ProcessReturnCode.hpp" #include "tool/Controller.hpp" + +int exit(const eprosima::spy::ProcessReturnCode& code); + + int main( int argc, char** argv) @@ -60,15 +64,15 @@ int main( if (arg_parse_result == eprosima::spy::ProcessReturnCode::help_argument) { - return static_cast(eprosima::spy::ProcessReturnCode::success); + return exit(eprosima::spy::ProcessReturnCode::success); } else if (arg_parse_result == eprosima::spy::ProcessReturnCode::version_argument) { - return static_cast(eprosima::spy::ProcessReturnCode::success); + return exit(eprosima::spy::ProcessReturnCode::success); } else if (arg_parse_result != eprosima::spy::ProcessReturnCode::success) { - return static_cast(arg_parse_result); + return exit(arg_parse_result); } // Check file is in args, else get the default file @@ -236,21 +240,23 @@ int main( "Error Loading Fast DDS Spy Configuration from file " << commandline_args.file_path << ". Error message:\n " << e.what()); - return static_cast(eprosima::spy::ProcessReturnCode::execution_failed); + return exit(eprosima::spy::ProcessReturnCode::execution_failed); } catch (const eprosima::utils::InitializationException& e) { EPROSIMA_LOG_ERROR(FASTDDSSPY_TOOL, "Error Initializing Fast DDS Spy. Error message:\n " << e.what()); - return static_cast(eprosima::spy::ProcessReturnCode::execution_failed); + return exit(eprosima::spy::ProcessReturnCode::execution_failed); } - // Force print every log before closing - eprosima::utils::Log::Flush(); + return exit(eprosima::spy::ProcessReturnCode::success); +} +int exit(const eprosima::spy::ProcessReturnCode& code) +{ // Delete the consumers before closing eprosima::utils::Log::ClearConsumers(); - return static_cast(eprosima::spy::ProcessReturnCode::success); + return static_cast(code); }