building block to easily create free function for logging in a library context
More...
building block to easily create free function for logging in a library context
#ifndef FOO_LOGGING_HPP_INCLUDED
#define FOO_LOGGING_HPP_INCLUDED
#include "iceoryx_hoofs/log/logging_free_function_building_block.hpp"
namespace foo
{
struct LoggingComponent
{
static constexpr char Ctx[] = "FOO";
static constexpr char Description[] = "Log context of the FOO component!";
};
static constexpr auto LogFatal = iox::log::ffbb::LogFatal<LoggingComponent>;
static constexpr auto LogError = iox::log::ffbb::LogError<LoggingComponent>;
static constexpr auto LogWarn = iox::log::ffbb::LogWarn<LoggingComponent>;
static constexpr auto LogInfo = iox::log::ffbb::LogInfo<LoggingComponent>;
static constexpr auto LogDebug = iox::log::ffbb::LogDebug<LoggingComponent>;
static constexpr auto LogVerbose = iox::log::ffbb::LogVerbose<LoggingComponent>;
}
#endif
namespace foo
{
constexpr char ComponentPosh::Ctx[];
constexpr char ComponentPosh::Description[];
}
void iox::errorHandler |
( |
const Error |
error, |
|
|
const std::function< void()> & |
errorCallBack = std::function< void()>() , |
|
|
const ErrorLevel |
level = ErrorLevel::FATAL |
|
) |
| |
|
noexcept |
Howto use the error handler correctly 1.) If the error you would like to handle is not listed in ICEORYX_ERRORS(error)... macro just add them like: error(MODULE_NAME__MY_FUNKY_ERROR) Attention: Create an error after the following convention: MODULE_NAME__A_CLEAR_BUT_SHORT_ERROR_DESCRIPTION And a long name is alright!
2.) Call errorHandler(Error::kMODULE_NAME__MY_FUNKY_ERROR); Please pay attention to the "k" prefix The defaults for errorCallback and ErrorLevel can also be overwritten: errorHandler( Error::kMODULE_NAME__MY_FUNKY_ERROR, []{ std::cout << "MyCustomCallback" << std::endl; }, ErrorLevel::MODERATE );
class PrettyClass {
float division(float a, float b) {
if ( b == 0.0f ) {
}
}
};
void errorHandler(const Error error, const std::function< void()> &errorCallBack=std::function< void()>(), const ErrorLevel level=ErrorLevel::FATAL) noexcept
Howto use the error handler correctly 1.) If the error you would like to handle is not listed in ICEO...
bool called = false;
auto temporaryErrorHandler = ErrorHandler::setTemporaryErrorHandler(
[&](
const Error e, std::function<
void()>,
const ErrorLevel) {
called = true;
});
ASSERT_TRUE(called);
ErrorLevel
the available error levels FATAL
Definition: error_handling.hpp:236