NebulaStream  0.6.213
NebulaStream is a data and application management framework for the internet of things
Logger.hpp File Reference
#include <Exceptions/NotImplementedException.hpp>
#include <Exceptions/SignalHandling.hpp>
#include <Identifiers/NESStrongTypeFormat.hpp>
#include <Util/Logger/LogLevel.hpp>
#include <Util/Logger/impl/NesLogger.hpp>
#include <Util/StacktraceLoader.hpp>
#include <iostream>
#include <memory>
#include <sstream>
Include dependency graph for Logger.hpp:

Classes

struct  NES::LogCaller< L >
 LogCaller is our compile-time trampoline to invoke the Logger method for the desired level of logging L. More...
 
struct  NES::LogCaller< LogLevel::LOG_INFO >
 
struct  NES::LogCaller< LogLevel::LOG_TRACE >
 
struct  NES::LogCaller< LogLevel::LOG_DEBUG >
 
struct  NES::LogCaller< LogLevel::LOG_ERROR >
 
struct  NES::LogCaller< LogLevel::LOG_FATAL_ERROR >
 
struct  NES::LogCaller< LogLevel::LOG_WARNING >
 

Namespaces

 NES
 This exception represents a network error.
 

Macros

#define NES_LOG(LEVEL, ...)
 this is the new logging macro that is the entry point for logging calls More...
 
#define NES_TRACE(...)   NES_LOG(NES::LogLevel::LOG_TRACE, __VA_ARGS__);
 
#define NES_INFO(...)   NES_LOG(NES::LogLevel::LOG_INFO, __VA_ARGS__);
 
#define NES_DEBUG(...)   NES_LOG(NES::LogLevel::LOG_DEBUG, __VA_ARGS__);
 
#define NES_WARNING(...)   NES_LOG(NES::LogLevel::LOG_WARNING, __VA_ARGS__);
 
#define NES_ERROR(...)   NES_LOG(NES::LogLevel::LOG_ERROR, __VA_ARGS__);
 
#define NES_FATAL_ERROR(...)   NES_LOG(NES::LogLevel::LOG_FATAL_ERROR, __VA_ARGS__);
 
#define NES_VERIFY(CONDITION, TEXT)   ((void) 0)
 
#define NES_DEBUG_PRINT_TRACE   false
 
#define NES_ASSERT(CONDITION, TEXT)
 
#define NES_ASSERT_THROW_EXCEPTION(CONDITION, EXCEPTION_TYPE, ...)
 
#define NES_ASSERT2_FMT(CONDITION, ...)
 
#define NES_THROW_RUNTIME_ERROR(...)
 
#define NES_NOT_IMPLEMENTED()
 
#define NES_ERROR_OR_THROW_RUNTIME(THROW_EXCEPTION, ...)
 

Macro Definition Documentation

◆ NES_ASSERT

#define NES_ASSERT (   CONDITION,
  TEXT 
)
Value:
do { \
if (!(CONDITION)) { \
std::stringstream textString; \
textString << TEXT; \
NES_ERROR("NES Fatal Error on {} message: {}", #CONDITION, textString.str()); \
auto __currentlevel = NES::getLogLevel(NES::Logger::getInstance()->getCurrentLogLevel()); \
if (__currentlevel >= __level && NES_COMPILE_TIME_LOG_LEVEL >= __level) { \
{ \
auto __stacktrace = NES::collectStacktrace(); \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << "Failed assertion on " #CONDITION; \
__os << " error message: " << TEXT; \
NES::Exceptions::invokeErrorHandlers(__buffer.str(), std::move(__stacktrace)); \
} \
} else { \
{ \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << "Failed assertion on " #CONDITION; \
__os << " error message: " << TEXT; \
} \
} \
} \
} while (0)

◆ NES_ASSERT2_FMT

#define NES_ASSERT2_FMT (   CONDITION,
  ... 
)
Value:
do { \
if (!(CONDITION)) { \
std::stringstream args; \
args << __VA_ARGS__; \
NES_ERROR("NES Fatal Error on {} message: {}", #CONDITION, args.str()); \
auto constexpr __level = NES::getLogLevel(NES::LogLevel::LOG_DEBUG); \
auto __currentlevel = NES::getLogLevel(NES::Logger::getInstance()->getCurrentLogLevel()); \
if (__currentlevel >= __level && NES_COMPILE_TIME_LOG_LEVEL >= __level) { \
auto __stacktrace = NES::collectStacktrace(); \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << "Failed assertion on " #CONDITION; \
__os << " error message: " << __VA_ARGS__; \
NES::Exceptions::invokeErrorHandlers(__buffer.str(), std::move(__stacktrace)); \
} else { \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << "Failed assertion on " #CONDITION; \
__os << " error message: " << __VA_ARGS__; \
} \
} \
} while (0)

◆ NES_ASSERT_THROW_EXCEPTION

#define NES_ASSERT_THROW_EXCEPTION (   CONDITION,
  EXCEPTION_TYPE,
  ... 
)
Value:
do { \
if (!(CONDITION)) { \
std::stringstream args; \
args << __VA_ARGS__; \
NES_ERROR("NES Fatal Error on {} message: {}", #CONDITION, args.str()); \
auto __currentlevel = NES::getLogLevel(NES::Logger::getInstance()->getCurrentLogLevel()); \
if (__currentlevel >= __level && NES_COMPILE_TIME_LOG_LEVEL >= __level) { \
{ \
auto __stacktrace = NES::collectAndPrintStacktrace(); \
} \
} \
\
{ \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << "Failed assertion on " #CONDITION; \
__os << " error message: " << __VA_ARGS__; \
throw EXCEPTION_TYPE(__buffer.str()); \
} \
} \
} while (0)

◆ NES_DEBUG

#define NES_DEBUG (   ...)    NES_LOG(NES::LogLevel::LOG_DEBUG, __VA_ARGS__);

◆ NES_DEBUG_PRINT_TRACE

#define NES_DEBUG_PRINT_TRACE   false

◆ NES_ERROR

#define NES_ERROR (   ...)    NES_LOG(NES::LogLevel::LOG_ERROR, __VA_ARGS__);

◆ NES_ERROR_OR_THROW_RUNTIME

#define NES_ERROR_OR_THROW_RUNTIME (   THROW_EXCEPTION,
  ... 
)
Value:
do { \
if ((THROW_EXCEPTION)) { \
NES_THROW_RUNTIME_ERROR(__VA_ARGS__); \
} else { \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << __VA_ARGS__; \
NES_ERROR("{}", __buffer.str()); \
} \
} while (0)

◆ NES_FATAL_ERROR

#define NES_FATAL_ERROR (   ...)    NES_LOG(NES::LogLevel::LOG_FATAL_ERROR, __VA_ARGS__);

◆ NES_INFO

#define NES_INFO (   ...)    NES_LOG(NES::LogLevel::LOG_INFO, __VA_ARGS__);

◆ NES_LOG

#define NES_LOG (   LEVEL,
  ... 
)
Value:
do { \
auto constexpr __level = NES::getLogLevel(LEVEL); \
if constexpr (NES_COMPILE_TIME_LOG_LEVEL >= __level) { \
NES::LogCaller<LEVEL>::do_call(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, __VA_ARGS__); \
} \
} while (0)

this is the new logging macro that is the entry point for logging calls

◆ NES_NOT_IMPLEMENTED

#define NES_NOT_IMPLEMENTED ( )
Value:
do { \
throw Exceptions::NotImplementedException("not implemented"); \
} while (0)

◆ NES_THROW_RUNTIME_ERROR

#define NES_THROW_RUNTIME_ERROR (   ...)
Value:
do { \
std::stringbuf __buffer; \
std::ostream __os(&__buffer); \
__os << __VA_ARGS__; \
auto __currentlevel = NES::getLogLevel(NES::Logger::getInstance()->getCurrentLogLevel()); \
if (__currentlevel >= __level && NES_COMPILE_TIME_LOG_LEVEL >= __level) { \
auto __stacktrace = NES::collectStacktrace(); \
throw NES::Exceptions::RuntimeException(__buffer.str(), std::move(__stacktrace), std::move(__location)); \
} else { \
throw NES::Exceptions::RuntimeException(__buffer.str(), "", std::move(__location)); \
} \
} while (0)

◆ NES_TRACE

#define NES_TRACE (   ...)    NES_LOG(NES::LogLevel::LOG_TRACE, __VA_ARGS__);

◆ NES_VERIFY

#define NES_VERIFY (   CONDITION,
  TEXT 
)    ((void) 0)

I am aware that we do not like __ before variable names but here we need them to avoid name collions, e.g., __buffer, __stacktrace that should not be a problem because of the scope, however, better be safe than sorry :P Additionally, we do not want to print stack traces when the currentLogLevel, as passed over at runtime in tests for example, is lower than DEBUG. Also, NES_DEBUG_MODE should be enabled as well. For that we define NES_DEBUG_PRINT_TRACE. When a stack trace should not be printed, an empty string will be given over instead, which is then handled appropriately in invokeErrorHandlers/RunTimeException.

◆ NES_WARNING

#define NES_WARNING (   ...)    NES_LOG(NES::LogLevel::LOG_WARNING, __VA_ARGS__);