From ee9e2c9259dba8ec2dfb3652dede6de896ce61df Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 28 Sep 2023 18:49:44 +0200 Subject: [PATCH] iox-#1755 Port error reporting the new logging macro --- .../custom/default/error_reporting.inl | 22 ++++++++++--------- .../error_reporting/error_logging.hpp | 20 +++++++++++------ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/custom/default/error_reporting.inl b/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/custom/default/error_reporting.inl index de1722535c..7d6bf7afd0 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/custom/default/error_reporting.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/custom/default/error_reporting.inl @@ -53,7 +53,7 @@ namespace er // Custom panic with location [[noreturn]] inline void panic(const SourceLocation& location) { - IOX_ERROR_INTERNAL_LOG_PANIC(location) << "Panic"; + IOX_ERROR_INTERNAL_LOG_PANIC(location, "Panic"); panic(); } @@ -63,7 +63,7 @@ namespace er template [[noreturn]] inline void panic(const SourceLocation& location, Message&& msg) { - IOX_ERROR_INTERNAL_LOG_PANIC(location) << "Panic " << msg; + IOX_ERROR_INTERNAL_LOG_PANIC(location, "Panic " << msg); panic(); } @@ -76,8 +76,9 @@ inline void report(const SourceLocation& location, Kind, const Error& error) auto moduleName = toModuleName(error); auto errorName = toErrorName(error); - IOX_ERROR_INTERNAL_LOG(location) << ": " << errorName << " (code " << code.value << ") in module " << moduleName - << " (id " << module.value << ")"; + IOX_ERROR_INTERNAL_LOG(location, + ": " << errorName << " (code " << code.value << ") in module " << moduleName << " (id " + << module.value << ")"); auto& h = ErrorHandler::get(); h.onReportError(ErrorDescriptor(location, code, module)); } @@ -95,8 +96,9 @@ inline void report(const SourceLocation& location, iox::er::FatalKind kind, cons auto moduleName = toModuleName(error); auto errorName = toErrorName(error); - IOX_ERROR_INTERNAL_LOG_FATAL(location) << ": " << kind.name << " " << errorName << " (code " << code.value - << ") in module " << moduleName << " (id " << module.value << ")"; + IOX_ERROR_INTERNAL_LOG_FATAL(location, + ": " << kind.name << " " << errorName << " (code " << code.value << ") in module " + << moduleName << " (id " << module.value << ")"); auto& h = ErrorHandler::get(); h.onReportError(ErrorDescriptor(location, code, module)); } @@ -106,7 +108,7 @@ inline void report(const SourceLocation& location, iox::er::PreconditionViolatio { auto code = toCode(error); auto module = toModule(error); - IOX_ERROR_INTERNAL_LOG_FATAL(location) << kind.name; + IOX_ERROR_INTERNAL_LOG_FATAL(location, kind.name); auto& h = ErrorHandler::get(); h.onReportViolation(ErrorDescriptor(location, code, module)); } @@ -116,7 +118,7 @@ inline void report(const SourceLocation& location, iox::er::AssumptionViolationK { auto code = toCode(error); auto module = toModule(error); - IOX_ERROR_INTERNAL_LOG_FATAL(location) << kind.name; + IOX_ERROR_INTERNAL_LOG_FATAL(location, kind.name); auto& h = ErrorHandler::get(); h.onReportViolation(ErrorDescriptor(location, code, module)); } @@ -127,7 +129,7 @@ report(const SourceLocation& location, iox::er::PreconditionViolationKind kind, { auto code = toCode(error); auto module = toModule(error); - IOX_ERROR_INTERNAL_LOG_FATAL(location) << kind.name << " " << std::forward(msg); + IOX_ERROR_INTERNAL_LOG_FATAL(location, kind.name << " " << std::forward(msg)); auto& h = ErrorHandler::get(); h.onReportViolation(ErrorDescriptor(location, code, module)); } @@ -138,7 +140,7 @@ report(const SourceLocation& location, iox::er::AssumptionViolationKind kind, co { auto code = toCode(error); auto module = toModule(error); - IOX_ERROR_INTERNAL_LOG_FATAL(location) << kind.name << " " << std::forward(msg); + IOX_ERROR_INTERNAL_LOG_FATAL(location, kind.name << " " << std::forward(msg)); auto& h = ErrorHandler::get(); h.onReportViolation(ErrorDescriptor(location, code, module)); } diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/error_logging.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/error_logging.hpp index f7c8269884..10e3932fc7 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/error_logging.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/error_reporting/error_logging.hpp @@ -25,19 +25,25 @@ /// @brief Log the location of an error. /// @param location the location of the error -#define IOX_ERROR_INTERNAL_LOG(location) \ - IOX_LOG_INTERNAL_LEGACY(location.file, location.line, location.function, iox::log::LogLevel::ERROR) \ - << location.file << " line " << location.line +#define IOX_ERROR_INTERNAL_LOG(location, msg_stream) \ + IOX_LOG_INTERNAL(location.file, \ + location.line, \ + location.function, \ + iox::log::LogLevel::ERROR, \ + location.file << " line " << location.line << ": " << msg_stream) /// @brief Log the location of a fatal error. /// @param location the location of the error -#define IOX_ERROR_INTERNAL_LOG_FATAL(location) \ - IOX_LOG_INTERNAL_LEGACY(location.file, location.line, location.function, iox::log::LogLevel::FATAL) \ - << location.file << " line " << location.line << ": " +#define IOX_ERROR_INTERNAL_LOG_FATAL(location, msg_stream) \ + IOX_LOG_INTERNAL(location.file, \ + location.line, \ + location.function, \ + iox::log::LogLevel::FATAL, \ + location.file << " line " << location.line << ": " << msg_stream) /// @brief Log a panic invocation. /// @param location the location of the panic invocation. -#define IOX_ERROR_INTERNAL_LOG_PANIC(location) IOX_ERROR_INTERNAL_LOG_FATAL(location) +#define IOX_ERROR_INTERNAL_LOG_PANIC(location, msg_stream) IOX_ERROR_INTERNAL_LOG_FATAL(location, msg_stream) // NOLINTEND(cppcoreguidelines-macro-usage, bugprone-macro-parentheses)