Skip to content

Commit

Permalink
iox-#1755 Port error reporting the new logging macro
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 28, 2023
1 parent 802110d commit bf088d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -63,7 +63,7 @@ namespace er
template <class Message>
[[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();
}

Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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<Message>(msg);
IOX_ERROR_INTERNAL_LOG_FATAL(location, kind.name << " " << std::forward<Message>(msg));
auto& h = ErrorHandler::get();
h.onReportViolation(ErrorDescriptor(location, code, module));
}
Expand All @@ -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<Message>(msg);
IOX_ERROR_INTERNAL_LOG_FATAL(location, kind.name << " " << std::forward<Message>(msg));
auto& h = ErrorHandler::get();
h.onReportViolation(ErrorDescriptor(location, code, module));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit bf088d2

Please sign in to comment.