Skip to content

iox🔗

building block to easily create free function for logging in a library context More...

Namespaces🔗

Name
iox::algorithm
iox::concurrent
iox::cxx
iox::log
iox::posix
iox::rp
iox::units

Classes🔗

Name
class iox::ErrorHandler
This handler is needed for unit testing, special debugging cases and other corner cases where we'd like to explicitly suppress the error handling.

Types🔗

Name
enum uint32_t Error { }
enum uint32_t ErrorLevel { FATAL, SEVERE, MODERATE }
the available error levels FATAL
using std::function< void(const Error error, const std::function< void()>, const ErrorLevel)> HandlerFunction
using cxx::string< MAX_IPC_CHANNEL_NAME_LENGTH > IpcChannelName_t

Functions🔗

Name
void errorHandler(const Error error, const std::function< void()> errorCallBack =std::function< void()>(), const ErrorLevel level =ErrorLevel::FATAL)
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!

Attributes🔗

Name
constexpr uint32_t MAX_IPC_CHANNEL_NAME_LENGTH

Detailed Description🔗

building block to easily create free function for logging in a library context

Todo: c function with only one valid value and an infinite number of invalid values are not useable with smart_c

// add this to e.g. foo_logging.hpp
// the logger can then be used with e.g. foo::LogInfo() of just LogInfo() in the same namespace

#ifndef FOO_LOGGING_HPP_INCLUDED
#define FOO_LOGGING_HPP_INCLUDED

#include "iceoryx_utils/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>;
} // namespace foo
#endif // FOO_LOGGING_HPP_INCLUDED


// this needs to be in foo_logging.cpp

namespace foo
{
    constexpr char ComponentPosh::Ctx[];
    constexpr char ComponentPosh::Description[];

} // namespace foo

Types Documentation🔗

enum Error🔗

Enumerator Value Description

enum ErrorLevel🔗

Enumerator Value Description
FATAL Log error entry + Assert + terminate.
SEVERE warning log entry + Assert
MODERATE warning log entry

the available error levels FATAL

  • Log message with FATAL
  • RouDi cannot recover from that error. RouDi is terminated
  • Assert (in DEBUG) and terminate
  • Reporting code must handle this and continue or go to a save state. Error handler could return (e.g. in test) SEVERE
  • Log message with ERROR
  • RouDi can still run. Error is reported
  • Assert in DEBUG, in RELEASE continue to run
  • Reporting code must handle this and continue MODERATE
  • Log message with ERROR
  • RouDi can still run. Error is reported
  • NO assert
  • Reporting code must handle this and continue

using HandlerFunction🔗

using iox::HandlerFunction = typedef std::function<void(const Error error, const std::function<void()>, const ErrorLevel)>;

using IpcChannelName_t🔗

using iox::IpcChannelName_t = typedef cxx::string<MAX_IPC_CHANNEL_NAME_LENGTH>;

Functions Documentation🔗

function errorHandler🔗

void errorHandler(
    const Error error,
    const std::function< void()> errorCallBack =std::function< void()>(),
    const ErrorLevel level =ErrorLevel::FATAL
)

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 ) {
            errorHandler(Error::kPRETTY_CLASS__DIVISION_BY_ZERO);
        }
    }
};
bool called = false;
auto temporaryErrorHandler = ErrorHandler::SetTemporaryErrorHandler(
    [&](const Error e, std::function<void()>, const ErrorLevel) {
        called = true;
    });

errorHandler(Error::kTEST__ASSERT_CALLED);
ASSERT_TRUE(called);

Attributes Documentation🔗

variable MAX_IPC_CHANNEL_NAME_LENGTH🔗

constexpr uint32_t MAX_IPC_CHANNEL_NAME_LENGTH = 100U;

Updated on 26 April 2021 at 15:31:01 CEST