ZeroErr
log.h File Reference
#include "zeroerr/internal/config.h"
#include "zeroerr/internal/threadsafe.h"
#include "zeroerr/internal/typetraits.h"
#include "zeroerr/dbg.h"
#include "zeroerr/format.h"
#include "zeroerr/print.h"
#include <chrono>
#include <map>
#include <string>
#include <vector>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  zeroerr::LogInfo
 LogInfo is a struct to store the meta data of the log message. More...
 
struct  zeroerr::LogMessage
 LogMessage is a class to store the log message. More...
 
struct  zeroerr::LogMessageImpl< T >
 LogMessageImpl is the implementation of the LogMessage. More...
 
struct  zeroerr::LogMessageImpl< T >::GetTuplePtr
 
struct  zeroerr::LogMessageImpl< T >::PrintTupleData
 
class  zeroerr::Logger
 
struct  zeroerr::PushResult
 
class  zeroerr::LogIterator
 LogIterator is a class to iterate the log messages. More...
 
class  zeroerr::LogStream
 LogStream is a class to manage the log messages. More...
 
class  zeroerr::IContextScope
 ContextScope is a helper class created in each basic block where you use INFO(). The context scope can has lazy evaluated function F(std::ostream&) that is called when the assertation is failed. More...
 
class  zeroerr::ContextScope< F >
 

Namespaces

 zeroerr
 
 zeroerr::detail
 

Macros

#define ZEROERR_INFO(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_INFO_(__VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ZEROERR_LOG(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(LOG_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ZEROERR_WARN(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(WARN_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ZEROERR_ERROR(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(ERROR_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define ZEROERR_FATAL(...)   ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(FATAL_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
 
#define INFO(...)   ZEROERR_INFO(__VA_ARGS__)
 
#define LOG(...)   ZEROERR_LOG(__VA_ARGS__)
 
#define WARN(...)   ZEROERR_WARN(__VA_ARGS__)
 
#define ERR(...)   ZEROERR_ERROR(__VA_ARGS__)
 
#define FATAL(...)   ZEROERR_FATAL(__VA_ARGS__)
 
#define VERBOSE(v)   ZEROERR_VERBOSE(v)
 
#define LOG_GET(func, id, name, type)   ZEROERR_LOG_GET(func, id, name, type)
 
#define ZEROERR_LOG_IF(condition, ACTION, ...)
 
#define INFO_IF(cond, ...)   ZEROERR_LOG_IF(cond, ZEROERR_INFO, __VA_ARGS__)
 
#define LOG_IF(cond, ...)   ZEROERR_LOG_IF(cond, ZEROERR_LOG, __VA_ARGS__)
 
#define WARN_IF(cond, ...)   ZEROERR_LOG_IF(cond, ZEROERR_WARN, __VA_ARGS__)
 
#define ERR_IF(cond, ...)   ZEROERR_LOG_IF(cond, ZEROERR_ERROR, __VA_ARGS__)
 
#define FATAL_IF(cond, ...)   ZEROERR_LOG_IF(cond, ZEROERR_FATAL, __VA_ARGS__)
 
#define ZEROERR_LOG_EVERY_(n, ACTION, ...)
 
#define INFO_EVERY_(n, ...)   ZEROERR_LOG_EVERY_(n, ZEROERR_INFO, __VA_ARGS__)
 
#define LOG_EVERY_(n, ...)   ZEROERR_LOG_EVERY_(n, ZEROERR_LOG, __VA_ARGS__)
 
#define WARN_EVERY_(n, ...)   ZEROERR_LOG_EVERY_(n, ZEROERR_WARN, __VA_ARGS__)
 
#define ERR_EVERY_(n, ...)   ZEROERR_LOG_EVERY_(n, ZEROERR_ERROR, __VA_ARGS__)
 
#define FATAL_EVERY_(n, ...)   ZEROERR_LOG_EVERY_(n, ZEROERR_FATAL, __VA_ARGS__)
 
#define ZEROERR_LOG_IF_EVERY_(n, cond, ACTION, ...)
 
#define INFO_IF_EVERY_(n, cond, ...)   ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_INFO, __VA_ARGS__)
 
#define LOG_IF_EVERY_(n, cond, ...)   ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_LOG, __VA_ARGS__)
 
#define WARN_IF_EVERY_(n, cond, ...)   ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_WARN, __VA_ARGS__)
 
#define ERR_IF_EVERY_(n, cond, ...)   ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
 
#define FATAL_IF_EVERY_(n, cond, ...)   ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_FATAL, __VA_ARGS__)
 
#define ZEROERR_LOG_FIRST(cond, ACTION, ...)
 
#define INFO_FIRST(cond, ...)   ZEROERR_LOG_FIRST(cond, ZEROERR_INFO, __VA_ARGS__)
 
#define LOG_FIRST(cond, ...)   ZEROERR_LOG_FIRST(cond, ZEROERR_LOG, __VA_ARGS__)
 
#define WARN_FIRST(cond, ...)   ZEROERR_LOG_FIRST(cond, ZEROERR_WARN, __VA_ARGS__)
 
#define ERR_FIRST(cond, ...)   ZEROERR_LOG_FIRST(cond, ZEROERR_ERROR, __VA_ARGS__)
 
#define FATAL_FIRST(cond, ...)   ZEROERR_LOG_FIRST(cond, ZEROERR_FATAL, __VA_ARGS__)
 
#define ZEROERR_LOG_FIRST_(n, cond, ACTION, ...)
 
#define INFO_FIRST_(n, cond, ...)   ZEROERR_LOG_FIRST_(n, cond, ZEROERR_INFO, __VA_ARGS__)
 
#define LOG_FIRST_(n, cond, ...)   ZEROERR_LOG_FIRST_(n, cond, ZEROERR_LOG, __VA_ARGS__)
 
#define WARN_FIRST_(n, cond, ...)   ZEROERR_LOG_FIRST_(n, cond, ZEROERR_WARN, __VA_ARGS__)
 
#define ERR_FIRST_(n, cond, ...)   ZEROERR_LOG_FIRST_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
 
#define FATAL_FIRST_(n, cond, ...)   ZEROERR_LOG_FIRST_(n, cond, ZEROERR_FATAL, __VA_ARGS__)
 
#define DLOG(ACTION, ...)
 
#define ZEROERR_VERBOSE(v)   if (zeroerr::_ZEROERR_G_VERBOSE >= (v))
 
#define ZEROERR_LOG_(severity, message, ...)
 
#define ZEROERR_INFO_(...)    ZEROERR_INFO_IMPL(ZEROERR_NAMEGEN(_capture_), ZEROERR_NAMEGEN(_capture_), __VA_ARGS__)
 
#define ZEROERR_INFO_IMPL(mb_name, v_name, ...)
 
#define ZEROERR_G_CONTEXT_SCOPE(x)
 
#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level, ...)    ZEROERR_LOG_IF(cond, level, __VA_ARGS__)
 
#define ZEROERR_LOG_GET(func, id, name, type)    zeroerr::LogStream::getDefault().getLog<type>(#func, id, #name)
 

Typedefs

typedef std::string(* zeroerr::LogCustomCallback) (const LogMessage &, bool colorful)
 

Enumerations

enum  zeroerr::LogSeverity {
  zeroerr::INFO_l , zeroerr::LOG_l , zeroerr::WARN_l , zeroerr::ERROR_l ,
  zeroerr::FATAL_l
}
 

Functions

template<typename T , unsigned... I>
std::string zeroerr::detail::gen_str (const char *msg, const T &args, seq< I... >)
 
template<typename T >
std::string zeroerr::detail::gen_str (const char *msg, const T &, seq<>)
 
void zeroerr::setLogLevel (LogSeverity level)
 set the log level More...
 
void zeroerr::setLogCategory (const char *categories)
 set the log category More...
 
void zeroerr::setLogCustomCallback (LogCustomCallback callback)
 set the log custom callback, this can support custom format of the log message More...
 
void zeroerr::suspendLog ()
 suspend the log to flush to the file More...
 
void zeroerr::resumeLog ()
 resume the log to flush to the file More...
 
template<typename... T>
PushResult zeroerr::log (T &&... args)
 
template<typename... T>
PushResult zeroerr::log (LogStream &stream, T &&... args)
 
template<typename F >
ContextScope< F > zeroerr::MakeContextScope (const F &f)
 

Variables

ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH const char * ZEROERR_LOG_CATEGORY
 

Macro Definition Documentation

◆ DLOG

#define DLOG (   ACTION,
  ... 
)

◆ ERR

#define ERR (   ...)    ZEROERR_ERROR(__VA_ARGS__)

◆ ERR_EVERY_

#define ERR_EVERY_ (   n,
  ... 
)    ZEROERR_LOG_EVERY_(n, ZEROERR_ERROR, __VA_ARGS__)

◆ ERR_FIRST

#define ERR_FIRST (   cond,
  ... 
)    ZEROERR_LOG_FIRST(cond, ZEROERR_ERROR, __VA_ARGS__)

◆ ERR_FIRST_

#define ERR_FIRST_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_FIRST_(n, cond, ZEROERR_ERROR, __VA_ARGS__)

◆ ERR_IF

#define ERR_IF (   cond,
  ... 
)    ZEROERR_LOG_IF(cond, ZEROERR_ERROR, __VA_ARGS__)

◆ ERR_IF_EVERY_

#define ERR_IF_EVERY_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_ERROR, __VA_ARGS__)

◆ FATAL

#define FATAL (   ...)    ZEROERR_FATAL(__VA_ARGS__)

◆ FATAL_EVERY_

#define FATAL_EVERY_ (   n,
  ... 
)    ZEROERR_LOG_EVERY_(n, ZEROERR_FATAL, __VA_ARGS__)

◆ FATAL_FIRST

#define FATAL_FIRST (   cond,
  ... 
)    ZEROERR_LOG_FIRST(cond, ZEROERR_FATAL, __VA_ARGS__)

◆ FATAL_FIRST_

#define FATAL_FIRST_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_FIRST_(n, cond, ZEROERR_FATAL, __VA_ARGS__)

◆ FATAL_IF

#define FATAL_IF (   cond,
  ... 
)    ZEROERR_LOG_IF(cond, ZEROERR_FATAL, __VA_ARGS__)

◆ FATAL_IF_EVERY_

#define FATAL_IF_EVERY_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_FATAL, __VA_ARGS__)

◆ INFO

#define INFO (   ...)    ZEROERR_INFO(__VA_ARGS__)

◆ INFO_EVERY_

#define INFO_EVERY_ (   n,
  ... 
)    ZEROERR_LOG_EVERY_(n, ZEROERR_INFO, __VA_ARGS__)

◆ INFO_FIRST

#define INFO_FIRST (   cond,
  ... 
)    ZEROERR_LOG_FIRST(cond, ZEROERR_INFO, __VA_ARGS__)

◆ INFO_FIRST_

#define INFO_FIRST_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_FIRST_(n, cond, ZEROERR_INFO, __VA_ARGS__)

◆ INFO_IF

#define INFO_IF (   cond,
  ... 
)    ZEROERR_LOG_IF(cond, ZEROERR_INFO, __VA_ARGS__)

◆ INFO_IF_EVERY_

#define INFO_IF_EVERY_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_INFO, __VA_ARGS__)

◆ LOG

#define LOG (   ...)    ZEROERR_LOG(__VA_ARGS__)

◆ LOG_EVERY_

#define LOG_EVERY_ (   n,
  ... 
)    ZEROERR_LOG_EVERY_(n, ZEROERR_LOG, __VA_ARGS__)

◆ LOG_FIRST

#define LOG_FIRST (   cond,
  ... 
)    ZEROERR_LOG_FIRST(cond, ZEROERR_LOG, __VA_ARGS__)

◆ LOG_FIRST_

#define LOG_FIRST_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_FIRST_(n, cond, ZEROERR_LOG, __VA_ARGS__)

◆ LOG_GET

#define LOG_GET (   func,
  id,
  name,
  type 
)    ZEROERR_LOG_GET(func, id, name, type)

◆ LOG_IF

#define LOG_IF (   cond,
  ... 
)    ZEROERR_LOG_IF(cond, ZEROERR_LOG, __VA_ARGS__)

◆ LOG_IF_EVERY_

#define LOG_IF_EVERY_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_LOG, __VA_ARGS__)

◆ VERBOSE

#define VERBOSE (   v)    ZEROERR_VERBOSE(v)

◆ WARN

#define WARN (   ...)    ZEROERR_WARN(__VA_ARGS__)

◆ WARN_EVERY_

#define WARN_EVERY_ (   n,
  ... 
)    ZEROERR_LOG_EVERY_(n, ZEROERR_WARN, __VA_ARGS__)

◆ WARN_FIRST

#define WARN_FIRST (   cond,
  ... 
)    ZEROERR_LOG_FIRST(cond, ZEROERR_WARN, __VA_ARGS__)

◆ WARN_FIRST_

#define WARN_FIRST_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_FIRST_(n, cond, ZEROERR_WARN, __VA_ARGS__)

◆ WARN_IF

#define WARN_IF (   cond,
  ... 
)    ZEROERR_LOG_IF(cond, ZEROERR_WARN, __VA_ARGS__)

◆ WARN_IF_EVERY_

#define WARN_IF_EVERY_ (   n,
  cond,
  ... 
)    ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_WARN, __VA_ARGS__)

◆ ZEROERR_ERROR

#define ZEROERR_ERROR (   ...)    ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(ERROR_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP

◆ ZEROERR_FATAL

#define ZEROERR_FATAL (   ...)    ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(FATAL_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP

◆ ZEROERR_G_CONTEXT_SCOPE

#define ZEROERR_G_CONTEXT_SCOPE (   x)
Value:
if (x) { \
i->str(std::cerr); \
} \
}
thread_local std::vector< IContextScope * > _ZEROERR_G_CONTEXT_SCOPE_VECTOR
Definition: log.cpp:20

◆ ZEROERR_INFO

◆ ZEROERR_INFO_

#define ZEROERR_INFO_ (   ...)     ZEROERR_INFO_IMPL(ZEROERR_NAMEGEN(_capture_), ZEROERR_NAMEGEN(_capture_), __VA_ARGS__)

◆ ZEROERR_INFO_IMPL

#define ZEROERR_INFO_IMPL (   mb_name,
  v_name,
  ... 
)
Value:
auto v_name = zeroerr::MakeContextScope([&](std::ostream& _capture_name) { \
Printer print(_capture_name); \
print.isQuoted = false; \
print(__VA_ARGS__); \
})
ContextScope< F > MakeContextScope(const F &f)
Definition: log.h:648

◆ ZEROERR_LOG

#define ZEROERR_LOG (   ...)    ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(LOG_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP

◆ ZEROERR_LOG_

#define ZEROERR_LOG_ (   severity,
  message,
  ... 
)
Value:
do { \
ZEROERR_G_CONTEXT_SCOPE(true); \
auto msg = zeroerr::log(__VA_ARGS__); \
\
static zeroerr::LogInfo log_info{__FILE__, \
__func__, \
message, \
ZEROERR_LOG_CATEGORY, \
__LINE__, \
msg.size, \
zeroerr::LogSeverity::severity}; \
msg.log->info = &log_info; \
if (msg.stream.getFlushMode() == zeroerr::LogStream::FlushMode::FLUSH_AT_ONCE) \
msg.stream.flush(); \
} while (0)
PushResult log(T &&... args)
Definition: log.h:613
LogInfo is a struct to store the meta data of the log message.
Definition: log.h:256
unsigned size
Definition: log.h:262

◆ ZEROERR_LOG_EVERY_

#define ZEROERR_LOG_EVERY_ (   n,
  ACTION,
  ... 
)
Value:
do { \
unsigned counter = 0; \
if (counter == 0) { \
counter = n; \
ACTION(__VA_ARGS__); \
} \
--counter; \
} while (0)

◆ ZEROERR_LOG_FIRST

#define ZEROERR_LOG_FIRST (   cond,
  ACTION,
  ... 
)
Value:
do { \
bool first = true; \
if (first && (cond)) { \
first = false; \
ACTION(__VA_ARGS__); \
} \
} while (0)

◆ ZEROERR_LOG_FIRST_

#define ZEROERR_LOG_FIRST_ (   n,
  cond,
  ACTION,
  ... 
)
Value:
do { \
unsigned counter = n; \
if (n-- && (cond)) { \
ACTION(__VA_ARGS__); \
} \
} while (0)

◆ ZEROERR_LOG_GET

#define ZEROERR_LOG_GET (   func,
  id,
  name,
  type 
)     zeroerr::LogStream::getDefault().getLog<type>(#func, id, #name)

◆ ZEROERR_LOG_IF

#define ZEROERR_LOG_IF (   condition,
  ACTION,
  ... 
)
Value:
do { \
if (condition) ACTION(__VA_ARGS__); \
} while (0)

◆ ZEROERR_LOG_IF_EVERY_

#define ZEROERR_LOG_IF_EVERY_ (   n,
  cond,
  ACTION,
  ... 
)
Value:
do { \
unsigned counter = 0; \
if (counter == 0 && (cond)) { \
counter = n; \
ACTION(__VA_ARGS__); \
} \
--counter; \
} while (0)

◆ ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER

#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER (   cond,
  level,
  ... 
)     ZEROERR_LOG_IF(cond, level, __VA_ARGS__)

◆ ZEROERR_VERBOSE

#define ZEROERR_VERBOSE (   v)    if (zeroerr::_ZEROERR_G_VERBOSE >= (v))

◆ ZEROERR_WARN

#define ZEROERR_WARN (   ...)    ZEROERR_SUPPRESS_VARIADIC_MACRO ZEROERR_EXPAND(ZEROERR_LOG_(WARN_l, __VA_ARGS__)) ZEROERR_SUPPRESS_VARIADIC_MACRO_POP

Variable Documentation

◆ ZEROERR_LOG_CATEGORY

ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH const char* ZEROERR_LOG_CATEGORY
extern