olp-cpp-sdk  1.22.0
Classes | Namespaces | Macros
Log.h File Reference

Provides the main interface for the logging library. More...

#include <cinttypes>
#include <cstdlib>
#include <sstream>
#include <string>
#include <olp/core/logging/Format.h>
#include <olp/core/logging/Level.h>
#include <olp/core/CoreApi.h>
#include <olp/core/utils/WarningWorkarounds.h>
#include <boost/optional.hpp>
Include dependency graph for Log.h:

Go to the source code of this file.

Classes

class  olp::logging::NullLogStream
 Used for disabled logs at compile time. More...
 
class  olp::logging::Log
 A primary interface for log messages. More...
 

Namespaces

 olp
 Rules all the other namespaces.
 

Macros

#define OLP_SDK_LOG_FUNCTION_SIGNATURE   __FUNCTION__
 Gets the current function signature for different compilers.
 
#define OLP_SDK_LOG_FILE   __FILE__
 
#define OLP_SDK_LOG_LINE   __LINE__
 
#define OLP_SDK_LOG_FUNCTION   __FUNCTION__
 
#define OLP_SDK_DO_LOG(level, tag, message)
 Logs a message using C++ style streams. More...
 
#define OLP_SDK_LOG_CRITICAL(level, tag, message)    OLP_SDK_DO_LOG(level, tag, message)
 Logs a "Critical" message using C++ style streams. More...
 
#define OLP_SDK_LOG_CRITICAL_INFO(tag, message)    OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Info, tag, message)
 Logs a "Critical info" message using C++ style streams. More...
 
#define OLP_SDK_LOG_CRITICAL_WARNING(tag, message)    OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Warning, tag, message)
 Logs a "Critical warning" message using C++ style streams. More...
 
#define OLP_SDK_LOG_CRITICAL_ERROR(tag, message)    OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Error, tag, message)
 Logs a "Critical error" message using C++ style streams. More...
 
#define OLP_SDK_LOG_FATAL(tag, message)    OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Fatal, tag, message)
 Logs a "Fatal error" message using C++ style streams. More...
 
#define OLP_SDK_LOG_ABORT(tag, message)
 Logs a "Critical fatal error" message using C++ style streams, and then aborts the program. More...
 
#define OLP_SDK_DO_LOG_F(level, tag, ...)
 Logs a message using the printf-style formatting. More...
 
#define OLP_SDK_LOG_CRITICAL_F(level, tag, ...)    OLP_SDK_DO_LOG_F(level, tag, __VA_ARGS__)
 Logs a "Critical" message using the printf-style formatting. More...
 
#define OLP_SDK_LOG_CRITICAL_INFO_F(tag, ...)    OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Info, tag, __VA_ARGS__)
 Logs a "Critical info" message using the printf-style formatting. More...
 
#define OLP_SDK_LOG_CRITICAL_WARNING_F(tag, ...)    OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Warning, tag, __VA_ARGS__)
 Logs a "Critical warning" message using the printf-style formatting. More...
 
#define OLP_SDK_LOG_CRITICAL_ERROR_F(tag, ...)    OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Error, tag, __VA_ARGS__)
 Logs a "Critical error" message using the printf-style formatting. More...
 
#define OLP_SDK_LOG_FATAL_F(tag, ...)    OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Fatal, tag, __VA_ARGS__)
 Logs a "Critical fatal error" message using the printf-style formatting. More...
 
#define OLP_SDK_LOG_ABORT_F(tag, ...)
 Logs a "Critical fatal error" message using the printf-style formatting, and then abort sthe program. More...
 
#define OLP_SDK_LOG(level, tag, message)
 Logs a message using C++ style streams. More...
 
#define OLP_SDK_LOG_TRACE(tag, message)    OLP_SDK_LOG(::olp::logging::Level::Trace, tag, message)
 Logs a "Trace" message using C++ style streams. More...
 
#define OLP_SDK_LOG_DEBUG(tag, message)    OLP_SDK_LOG(::olp::logging::Level::Debug, tag, message)
 Logs a "Debug" message using C++ style streams. More...
 
#define OLP_SDK_LOG_INFO(tag, message)    OLP_SDK_LOG(::olp::logging::Level::Info, tag, message)
 Logs an "Info" message using C++ style streams. More...
 
#define OLP_SDK_LOG_WARNING(tag, message)    OLP_SDK_LOG(::olp::logging::Level::Warning, tag, message)
 Logs a "Warning" message using C++ style streams. More...
 
#define OLP_SDK_LOG_ERROR(tag, message)    OLP_SDK_LOG(::olp::logging::Level::Error, tag, message)
 Logs an "Error" message using C++ style streams. More...
 
#define OLP_SDK_LOG_F(level, tag, ...)
 Logs a message using the printf style formatting. More...
 
#define OLP_SDK_LOG_TRACE_F(tag, ...)    OLP_SDK_LOG_F(::olp::logging::Level::Trace, tag, __VA_ARGS__)
 Logs a "Trace" message using the printf style formatting. More...
 
#define OLP_SDK_LOG_DEBUG_F(tag, ...)    OLP_SDK_LOG_F(::olp::logging::Level::Debug, tag, __VA_ARGS__)
 Logs a "Debug" message using the printf style formatting. More...
 
#define OLP_SDK_LOG_INFO_F(tag, ...)    OLP_SDK_LOG_F(::olp::logging::Level::Info, tag, __VA_ARGS__)
 Logs an "Info" message using the printf style formatting. More...
 
#define OLP_SDK_LOG_WARNING_F(tag, ...)    OLP_SDK_LOG_F(::olp::logging::Level::Warning, tag, __VA_ARGS__)
 Logs a "Warning" message using the printf style formatting. More...
 
#define OLP_SDK_LOG_ERROR_F(tag, ...)    OLP_SDK_LOG_F(::olp::logging::Level::Error, tag, __VA_ARGS__)
 Logs an "Eror" message using the printf style formatting. More...
 

Detailed Description

Provides the main interface for the logging library.

Macro Definition Documentation

◆ OLP_SDK_DO_LOG

#define OLP_SDK_DO_LOG (   level,
  tag,
  message 
)
Value:
do { \
std::ostringstream __strm; \
__strm << message; \
level, tag, __strm.str(), OLP_SDK_LOG_FILE, OLP_SDK_LOG_LINE, \
OLP_SDK_LOG_FUNCTION, OLP_SDK_LOG_FUNCTION_SIGNATURE); \
} \
OLP_SDK_CORE_LOOP_ONCE()
#define OLP_SDK_LOG_FUNCTION_SIGNATURE
Gets the current function signature for different compilers.
Definition: Log.h:57
static void logMessage(Level level, const std::string &tag, const std::string &message, const char *file, unsigned int line, const char *function, const char *fullFunction)
Logs a message to the registered appenders.

Logs a message using C++ style streams.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
levelThe log level.
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_DO_LOG_F

#define OLP_SDK_DO_LOG_F (   level,
  tag,
  ... 
)
Value:
do { \
std::string __message = ::olp::logging::format(__VA_ARGS__); \
::olp::logging::Log::logMessage(level, tag, __message, OLP_SDK_LOG_FILE, \
OLP_SDK_LOG_LINE, OLP_SDK_LOG_FUNCTION, \
} \
OLP_SDK_CORE_LOOP_ONCE()

Logs a message using the printf-style formatting.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
levelThe log level.
tagThe tag for the log component.

◆ OLP_SDK_LOG

#define OLP_SDK_LOG (   level,
  tag,
  message 
)
Value:
do { \
if (::olp::logging::Log::isEnabled(level, tag)) { \
OLP_SDK_DO_LOG(level, tag, message); \
} \
} \
OLP_SDK_CORE_LOOP_ONCE()
static bool isEnabled(Level level)
Checks whether a level is enabled by default.

Logs a message using C++ style streams.

Parameters
levelThe log level.
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_ABORT

#define OLP_SDK_LOG_ABORT (   tag,
  message 
)
Value:
do { \
OLP_SDK_LOG_FATAL(tag, message); \
std::abort(); \
} \
OLP_SDK_CORE_LOOP_ONCE()

Logs a "Critical fatal error" message using C++ style streams, and then aborts the program.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_ABORT_F

#define OLP_SDK_LOG_ABORT_F (   tag,
  ... 
)
Value:
do { \
OLP_SDK_LOG_FATAL_F(tag, __VA_ARGS__); \
std::abort(); \
} \
OLP_SDK_CORE_LOOP_ONCE()

Logs a "Critical fatal error" message using the printf-style formatting, and then abort sthe program.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_CRITICAL

#define OLP_SDK_LOG_CRITICAL (   level,
  tag,
  message 
)     OLP_SDK_DO_LOG(level, tag, message)

Logs a "Critical" message using C++ style streams.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
levelThe log level.
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_CRITICAL_ERROR

#define OLP_SDK_LOG_CRITICAL_ERROR (   tag,
  message 
)     OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Error, tag, message)

Logs a "Critical error" message using C++ style streams.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_CRITICAL_ERROR_F

#define OLP_SDK_LOG_CRITICAL_ERROR_F (   tag,
  ... 
)     OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Error, tag, __VA_ARGS__)

Logs a "Critical error" message using the printf-style formatting.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_CRITICAL_F

#define OLP_SDK_LOG_CRITICAL_F (   level,
  tag,
  ... 
)     OLP_SDK_DO_LOG_F(level, tag, __VA_ARGS__)

Logs a "Critical" message using the printf-style formatting.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
levelThe log level.
tagThe tag for the log component.

◆ OLP_SDK_LOG_CRITICAL_INFO

#define OLP_SDK_LOG_CRITICAL_INFO (   tag,
  message 
)     OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Info, tag, message)

Logs a "Critical info" message using C++ style streams.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_CRITICAL_INFO_F

#define OLP_SDK_LOG_CRITICAL_INFO_F (   tag,
  ... 
)     OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Info, tag, __VA_ARGS__)

Logs a "Critical info" message using the printf-style formatting.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_CRITICAL_WARNING

#define OLP_SDK_LOG_CRITICAL_WARNING (   tag,
  message 
)     OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Warning, tag, message)

Logs a "Critical warning" message using C++ style streams.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_CRITICAL_WARNING_F

#define OLP_SDK_LOG_CRITICAL_WARNING_F (   tag,
  ... 
)     OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Warning, tag, __VA_ARGS__)

Logs a "Critical warning" message using the printf-style formatting.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_DEBUG

#define OLP_SDK_LOG_DEBUG (   tag,
  message 
)     OLP_SDK_LOG(::olp::logging::Level::Debug, tag, message)

Logs a "Debug" message using C++ style streams.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_DEBUG_F

#define OLP_SDK_LOG_DEBUG_F (   tag,
  ... 
)     OLP_SDK_LOG_F(::olp::logging::Level::Debug, tag, __VA_ARGS__)

Logs a "Debug" message using the printf style formatting.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_ERROR

#define OLP_SDK_LOG_ERROR (   tag,
  message 
)     OLP_SDK_LOG(::olp::logging::Level::Error, tag, message)

Logs an "Error" message using C++ style streams.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_ERROR_F

#define OLP_SDK_LOG_ERROR_F (   tag,
  ... 
)     OLP_SDK_LOG_F(::olp::logging::Level::Error, tag, __VA_ARGS__)

Logs an "Eror" message using the printf style formatting.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_F

#define OLP_SDK_LOG_F (   level,
  tag,
  ... 
)
Value:
do { \
if (::olp::logging::Log::isEnabled(level, tag)) { \
OLP_SDK_DO_LOG_F(level, tag, __VA_ARGS__); \
} \
} \
OLP_SDK_CORE_LOOP_ONCE()

Logs a message using the printf style formatting.

Parameters
levelThe log level.
tagThe tag for the log component.

◆ OLP_SDK_LOG_FATAL

#define OLP_SDK_LOG_FATAL (   tag,
  message 
)     OLP_SDK_LOG_CRITICAL(::olp::logging::Level::Fatal, tag, message)

Logs a "Fatal error" message using C++ style streams.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_FATAL_F

#define OLP_SDK_LOG_FATAL_F (   tag,
  ... 
)     OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Fatal, tag, __VA_ARGS__)

Logs a "Critical fatal error" message using the printf-style formatting.

OLP_SDK_LOGGING_DISABLED does not disable this functionality. Additionally, it does not check to see if the tag is disabled.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_INFO

#define OLP_SDK_LOG_INFO (   tag,
  message 
)     OLP_SDK_LOG(::olp::logging::Level::Info, tag, message)

Logs an "Info" message using C++ style streams.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_INFO_F

#define OLP_SDK_LOG_INFO_F (   tag,
  ... 
)     OLP_SDK_LOG_F(::olp::logging::Level::Info, tag, __VA_ARGS__)

Logs an "Info" message using the printf style formatting.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_TRACE

#define OLP_SDK_LOG_TRACE (   tag,
  message 
)     OLP_SDK_LOG(::olp::logging::Level::Trace, tag, message)

Logs a "Trace" message using C++ style streams.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_TRACE_F

#define OLP_SDK_LOG_TRACE_F (   tag,
  ... 
)     OLP_SDK_LOG_F(::olp::logging::Level::Trace, tag, __VA_ARGS__)

Logs a "Trace" message using the printf style formatting.

Parameters
tagThe tag for the log component.

◆ OLP_SDK_LOG_WARNING

#define OLP_SDK_LOG_WARNING (   tag,
  message 
)     OLP_SDK_LOG(::olp::logging::Level::Warning, tag, message)

Logs a "Warning" message using C++ style streams.

Parameters
tagThe tag for the log component.
messageThe log message.

◆ OLP_SDK_LOG_WARNING_F

#define OLP_SDK_LOG_WARNING_F (   tag,
  ... 
)     OLP_SDK_LOG_F(::olp::logging::Level::Warning, tag, __VA_ARGS__)

Logs a "Warning" message using the printf style formatting.

Parameters
tagThe tag for the log component.