iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
iox2::legacy::log Namespace Reference

Namespaces

namespace  internal
 

Classes

class  ConsoleLogger
 A minimal logger implementation which outputs the log messages to the console. More...
 
class  LogBin
 Helper struct to log in binary format. More...
 
struct  LogBuffer
 Provides access to the log buffer if direct access is required. More...
 
class  LogHex
 Helper struct to log in hexadecimal format. More...
 
class  LogOct
 Helper struct to log in octal format. More...
 
class  LogRaw
 Helper struct to log in raw bytes. More...
 
class  LogStream
 This class provides the public interface to the logger and is used with the 'IOX2_LOG' macro. In order to add support for custom data types 'operator<<' needs to be implement for the custom type. More...
 

Typedefs

using Logger = internal::Logger< ConsoleLogger >
 
using TestingLoggerBase = internal::Logger< ConsoleLogger >
 

Enumerations

enum class  LogLevel : uint8_t {
  Off = 0 , Fatal , Error , Warn ,
  Info , Debug , Trace
}
 This enum defines the log levels used for logging. More...
 

Functions

constexpr const charlogLevelDisplayColor (const LogLevel value) noexcept
 converts LogLevel into a string literal color code
 
constexpr const charlogLevelDisplayText (const LogLevel value) noexcept
 converts LogLevel into a string literal display text
 
constexpr const charasStringLiteral (const LogLevel value) noexcept
 converts LogLevel into a string literal
 
template<uint32_t N>
bool equalStrings (const char *lhs, const char(&rhs)[N]) noexcept
 Compares C-style strings with a char array, i.g. string literal for equality.
 
LogLevel logLevelFromEnvOr (const LogLevel logLevel) noexcept
 Tries to get the log level from the 'IOX2_LOG_LEVEL' env variable or uses the specified one if the env variable is not set.
 
template<typename T , typename = std::enable_if_t<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value>>
constexpr LogHex< Thex (const T value) noexcept
 Log a number in hexadecimal format.
 
constexpr LogHex< const void *consthex (const void *const ptr) noexcept
 Log a pointer in hexadecimal format.
 
template<typename T , typename = std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value>>
constexpr LogOct< Toct (const T value) noexcept
 Log a number in octal format.
 
template<typename T , typename = std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value>>
constexpr LogBin< Tbin (const T value) noexcept
 Log a number in binary format.
 
template<typename T >
constexpr std::enable_if<!std::is_pointer< T >::value, LogRaw >::type raw (const T &object) noexcept
 Log an object in raw bytes.
 
constexpr LogRaw raw (const void *const data, const uint64_t size) noexcept
 Log data in raw bytes.
 

Variables

template<typename T >
static constexpr const charLOG_FORMAT_DEC { internal::logFormatDec<T>() }
 printf-like format string for decimal formatting of numbers
 
template<typename T >
static constexpr const charLOG_FORMAT_HEX { internal::logFormatHex<T>() }
 printf-like format string for hexadecimal formatting of numbers
 
template<typename T >
static constexpr const charLOG_FORMAT_OCT { internal::logFormatOct<T>() }
 printf-like format string for octal formatting of numbers
 
static constexpr bool IGNORE_ACTIVE_LOG_LEVEL { false }
 If set to true, the IOX2_LOG macro will ignore the the configured log level and forward all messages to the logger. This is useful in cases the default ConsoleLogger is replaced by a custom logger which does the filtering by itself.
 
static constexpr LogLevel MINIMAL_LOG_LEVEL { LogLevel::Trace }
 The minimal log level which will be compiled into the application. All log levels below this will be optimized out at compile time.
 

Typedef Documentation

◆ Logger

◆ TestingLoggerBase

Enumeration Type Documentation

◆ LogLevel

This enum defines the log levels used for logging.

Enumerator
Off 
Fatal 
Error 
Warn 
Info 
Debug 
Trace 

Definition at line 30 of file logger.hpp.

Function Documentation

◆ asStringLiteral()

constexpr const char * iox2::legacy::log::asStringLiteral ( const LogLevel  value)
constexprnoexcept

converts LogLevel into a string literal

Parameters
[in]valuethe LogLevel to convert
Returns
string literal of the LogLevel value

◆ bin()

template<typename T , typename = std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value>>
constexpr LogBin< T > iox2::legacy::log::bin ( const T  value)
constexprnoexcept

Log a number in binary format.

Template Parameters

in] T the integral data type of the value to log

Parameters
[in]valueto be logged
Returns
a helper struct which will be used by the LogStream

◆ equalStrings()

template<uint32_t N>
bool iox2::legacy::log::equalStrings ( const char lhs,
const char(&)  rhs[N] 
)
noexcept

Compares C-style strings with a char array, i.g. string literal for equality.

Todo:
iox-#1755 move this to e.g. helplets once we are able to depend on on it
Template Parameters

in] N size of the char array

Parameters
[in]lhsC-style string to compare
[in]rhschar array to compare
Returns
true if the strings are equal, false otherwise

◆ hex() [1/2]

template<typename T , typename = std::enable_if_t<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value>>
constexpr LogHex< T > iox2::legacy::log::hex ( const T  value)
constexprnoexcept

Log a number in hexadecimal format.

Template Parameters

in] T the arithmetic data type of the value to log

Parameters
[in]valueto be logged
Returns
a helper struct which will be used by the LogStream

◆ hex() [2/2]

constexpr LogHex< const void *const > iox2::legacy::log::hex ( const void *const  ptr)
constexprnoexcept

Log a pointer in hexadecimal format.

Parameters
[in]ptris the pointer to be logged
Returns
a helper struct which will be used by the LogStream

◆ logLevelDisplayColor()

constexpr const char * iox2::legacy::log::logLevelDisplayColor ( const LogLevel  value)
constexprnoexcept

converts LogLevel into a string literal color code

Parameters
[in]valuethe LogLevel to convert
Returns
string literal of the corresponding color code

◆ logLevelDisplayText()

constexpr const char * iox2::legacy::log::logLevelDisplayText ( const LogLevel  value)
constexprnoexcept

converts LogLevel into a string literal display text

Parameters
[in]valuethe LogLevel to convert
Returns
string literal of the display text

◆ logLevelFromEnvOr()

LogLevel iox2::legacy::log::logLevelFromEnvOr ( const LogLevel  logLevel)
noexcept

Tries to get the log level from the 'IOX2_LOG_LEVEL' env variable or uses the specified one if the env variable is not set.

Parameters
[in]logLevelis the log level to be used when the env variable is not set
Note
The function uses 'getenv' which is not thread safe and can result in undefined behavior when it is called from multiple threads or the env variable is changed while the function holds a pointer to the data. For this reason the function should only be used in the startup phase of the application and only in the main thread.

◆ oct()

template<typename T , typename = std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value>>
constexpr LogOct< T > iox2::legacy::log::oct ( const T  value)
constexprnoexcept

Log a number in octal format.

Template Parameters

in] T the integral data type of the value to log

Parameters
[in]valueto be logged
Returns
a helper struct which will be used by the LogStream

◆ raw() [1/2]

template<typename T >
constexpr std::enable_if<!std::is_pointer< T >::value, LogRaw >::type iox2::legacy::log::raw ( const T object)
constexprnoexcept

Log an object in raw bytes.

Template Parameters

in] T the data type of the object to log

Parameters
[in]objectto be logged
Returns
a helper struct which will be used by the LogStream

◆ raw() [2/2]

constexpr LogRaw iox2::legacy::log::raw ( const void *const  data,
const uint64_t  size 
)
constexprnoexcept

Log data in raw bytes.

Parameters
[in]datapointer to the data to be logged
[in]sizeof the data to be logged
Returns
a helper struct which will be used by the LogStream

Variable Documentation

◆ IGNORE_ACTIVE_LOG_LEVEL

constexpr bool iox2::legacy::log::IGNORE_ACTIVE_LOG_LEVEL { false }
staticconstexpr

If set to true, the IOX2_LOG macro will ignore the the configured log level and forward all messages to the logger. This is useful in cases the default ConsoleLogger is replaced by a custom logger which does the filtering by itself.

Todo:
iox-#1755 make this a option a cmake argument and use via a compile define
Note
This has an performance impact if set to true since the lazy evaluation of the logged data will be jimmied.

Definition at line 42 of file logger.hpp.

Referenced by iox2::legacy::log::internal::is_log_level_active().

◆ LOG_FORMAT_DEC

template<typename T >
constexpr const char* iox2::legacy::log::LOG_FORMAT_DEC { internal::logFormatDec<T>() }
staticconstexpr

printf-like format string for decimal formatting of numbers

Definition at line 114 of file logformat.hpp.

◆ LOG_FORMAT_HEX

template<typename T >
constexpr const char* iox2::legacy::log::LOG_FORMAT_HEX { internal::logFormatHex<T>() }
staticconstexpr

printf-like format string for hexadecimal formatting of numbers

Definition at line 118 of file logformat.hpp.

◆ LOG_FORMAT_OCT

template<typename T >
constexpr const char* iox2::legacy::log::LOG_FORMAT_OCT { internal::logFormatOct<T>() }
staticconstexpr

printf-like format string for octal formatting of numbers

Definition at line 122 of file logformat.hpp.

◆ MINIMAL_LOG_LEVEL

constexpr LogLevel iox2::legacy::log::MINIMAL_LOG_LEVEL { LogLevel::Trace }
staticconstexpr

The minimal log level which will be compiled into the application. All log levels below this will be optimized out at compile time.

Note
This is different than IGNORE_ACTIVE_LOG_LEVEL since the active log level could still be set to off at runtime

Definition at line 47 of file logger.hpp.

Referenced by iox2::legacy::log::internal::is_log_level_active().