diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index ab776ee873..7efc897d2e 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -114,6 +114,7 @@ iox_add_library( reporting/source/hoofs_error_reporting.cpp reporting/source/console_logger.cpp reporting/source/logger.cpp + reporting/source/logging.cpp time/source/duration.cpp utility/source/unique_id.cpp diff --git a/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl b/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl index d6a9a55ca0..f5d6583fff 100644 --- a/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl +++ b/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl @@ -111,6 +111,7 @@ inline void Logger::initLoggerInternal(const LogLevel logLevel) noex { BaseLogger::setLogLevel(logLevel); BaseLogger::initLogger(logLevel); + iox_platform_set_log_backend(&platform_log_backend); m_isFinalized.store(true, std::memory_order_relaxed); } else diff --git a/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp b/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp index 6704fcf2b9..9a2c2a876e 100644 --- a/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp +++ b/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp @@ -18,6 +18,7 @@ #ifndef IOX_HOOFS_REPORTING_LOG_BUILDING_BLOCKS_LOGGER_HPP #define IOX_HOOFS_REPORTING_LOG_BUILDING_BLOCKS_LOGGER_HPP +#include "iceoryx_platform/logging.hpp" #include "iox/iceoryx_hoofs_types.hpp" #include @@ -52,6 +53,12 @@ LogLevel logLevelFromEnvOr(const LogLevel logLevel) noexcept; namespace internal { +/// @brief The backend for the platform logging frontend +/// @copydoc IceoryxPlatformLogBackend +/// @note Needs to be implemented in 'logging.cpp' in order to use the high level log API +void platform_log_backend( + const char* file, int line, const char* function, IceoryxPlatformLogLevel log_level, const char* msg); + /// @brief This class acts as common interface for the Logger. It provides the common functionality and inherits from /// the BaseLogger which is provided as template parameter. Please have a look at the design document for more details. /// @tparam[in] BaseLogger is the actual implementation diff --git a/iceoryx_hoofs/reporting/source/logging.cpp b/iceoryx_hoofs/reporting/source/logging.cpp new file mode 100644 index 0000000000..0661d45cc3 --- /dev/null +++ b/iceoryx_hoofs/reporting/source/logging.cpp @@ -0,0 +1,40 @@ + +#include "iox/logging.hpp" + +namespace iox::log::internal +{ +// NOLINTJUSTIFICATION Not used directly but as a function pointer to set the backend +// NOLINTNEXTLINE(readability-function-size) +void platform_log_backend( + const char* file, int line, const char* function, IceoryxPlatformLogLevel log_level, const char* msg) +{ + auto level = LogLevel::TRACE; + switch (log_level) + { + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_OFF: + level = LogLevel::OFF; + break; + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_FATAL: + level = LogLevel::FATAL; + break; + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_ERROR: + level = LogLevel::ERROR; + break; + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_WARN: + level = LogLevel::WARN; + break; + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_INFO: + level = LogLevel::INFO; + break; + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_DEBUG: + level = LogLevel::DEBUG; + break; + case IceoryxPlatformLogLevel::IOX_PLATFORM_LOG_LEVEL_TRACE: + level = LogLevel::TRACE; + break; + default: + level = LogLevel::TRACE; + } + IOX_LOG_INTERNAL(file, line, function, level, msg); +} +} // namespace iox::log::internal