ZeroErr
Loading...
Searching...
No Matches
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 "zeroerr/internal/time.h"
#include <iosfwd>
#include <cstddef>
#include <map>
#include "zeroerr/string.h"
#include <utility>
#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...
struct  zeroerr::LogRecord< T >
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(zeroerr::StringBuffer&) that is called when the assertation is failed. More...
class  zeroerr::ContextScope< F >
 Template implementation of context scope. More...

Namespaces

namespace  zeroerr
namespace  zeroerr::detail

Macros

#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
#define ZEROERR_INFO(...)
#define ZEROERR_LOG(...)
#define ZEROERR_WARN(...)
#define ZEROERR_ERROR(...)
#define ZEROERR_FATAL(...)
#define INFO(...)
#define LOG(...)
#define WARN(...)
#define ERR(...)
#define FATAL(...)
#define VERBOSE(v)
#define LOG_GET(func, id, name, type)
#define ZEROERR_LOG_IF(condition, ACTION, ...)
#define INFO_IF(cond, ...)
#define LOG_IF(cond, ...)
#define WARN_IF(cond, ...)
#define ERR_IF(cond, ...)
#define FATAL_IF(cond, ...)
#define ZEROERR_LOG_EVERY_(n, ACTION, ...)
#define INFO_EVERY_(n, ...)
#define LOG_EVERY_(n, ...)
#define WARN_EVERY_(n, ...)
#define ERR_EVERY_(n, ...)
#define FATAL_EVERY_(n, ...)
#define ZEROERR_LOG_IF_EVERY_(n, cond, ACTION, ...)
#define INFO_IF_EVERY_(n, cond, ...)
#define LOG_IF_EVERY_(n, cond, ...)
#define WARN_IF_EVERY_(n, cond, ...)
#define ERR_IF_EVERY_(n, cond, ...)
#define FATAL_IF_EVERY_(n, cond, ...)
#define ZEROERR_LOG_FIRST(cond, ACTION, ...)
#define INFO_FIRST(cond, ...)
#define LOG_FIRST(cond, ...)
#define WARN_FIRST(cond, ...)
#define ERR_FIRST(cond, ...)
#define FATAL_FIRST(cond, ...)
#define ZEROERR_LOG_FIRST_(n, cond, ACTION, ...)
#define INFO_FIRST_(n, cond, ...)
#define LOG_FIRST_(n, cond, ...)
#define WARN_FIRST_(n, cond, ...)
#define ERR_FIRST_(n, cond, ...)
#define FATAL_FIRST_(n, cond, ...)
#define DLOG(ACTION, ...)
#define ZEROERR_VERBOSE(v)
#define ZEROERR_LOG_(severity, message, ...)
#define ZEROERR_INFO_(...)
#define ZEROERR_INFO_IMPL(mb_name, v_name, ...)
#define ZEROERR_G_CONTEXT_SCOPE(x)
#define ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER(cond, level, ...)
#define ZEROERR_LOG_GET(func, id, name, type)

Typedefs

typedef zeroerr::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>
zeroerr::String zeroerr::detail::gen_str (const char *msg, const T &args, seq< I... >)
template<typename T>
zeroerr::String zeroerr::detail::gen_str (const char *msg, const T &, seq<>)
void zeroerr::setLogLevel (LogSeverity level)
 set the log level
void zeroerr::setLogCategory (const char *categories)
 set the log category
void zeroerr::setLogCustomCallback (LogCustomCallback callback)
 set the log custom callback, this can support custom format of the log message
void zeroerr::suspendLog ()
 suspend the log to flush to the file
void zeroerr::resumeLog ()
 resume the log to flush to the file
template<typename... T>
LogRecord< T... > zeroerr::makeLogRecord (LogStream &stream, T &&... args)
template<typename... T>
LogRecord< T... > zeroerr::makeLogRecord (T &&... args)
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)
 Helper function to create a context scope.

Variables

ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH const char * ZEROERR_LOG_CATEGORY

Macro Definition Documentation

◆ _LIBCPP_REMOVE_TRANSITIVE_INCLUDES

#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES

◆ DLOG

#define DLOG ( ACTION,
... )

◆ ERR

#define ERR ( ...)
Value:
ZEROERR_ERROR(__VA_ARGS__)
#define ZEROERR_ERROR(...)
Definition log.h:38

◆ ERR_EVERY_

#define ERR_EVERY_ ( n,
... )
Value:
#define ZEROERR_LOG_EVERY_(n, ACTION,...)
Definition log.h:92

◆ ERR_FIRST

#define ERR_FIRST ( cond,
... )
Value:
ZEROERR_LOG_FIRST(cond, ZEROERR_ERROR, __VA_ARGS__)
#define ZEROERR_LOG_FIRST(cond, ACTION,...)
Definition log.h:128

◆ ERR_FIRST_

#define ERR_FIRST_ ( n,
cond,
... )
Value:
ZEROERR_LOG_FIRST_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
#define ZEROERR_LOG_FIRST_(n, cond, ACTION,...)
Definition log.h:143

◆ ERR_IF

#define ERR_IF ( cond,
... )
Value:
ZEROERR_LOG_IF(cond, ZEROERR_ERROR, __VA_ARGS__)
#define ZEROERR_LOG_IF(condition, ACTION,...)
Definition log.h:79

◆ ERR_IF_EVERY_

#define ERR_IF_EVERY_ ( n,
cond,
... )
Value:
ZEROERR_LOG_IF_EVERY_(n, cond, ZEROERR_ERROR, __VA_ARGS__)
#define ZEROERR_LOG_IF_EVERY_(n, cond, ACTION,...)
Definition log.h:110

◆ FATAL

#define FATAL ( ...)
Value:
ZEROERR_FATAL(__VA_ARGS__)
#define ZEROERR_FATAL(...)
Definition log.h:39

◆ FATAL_EVERY_

#define FATAL_EVERY_ ( n,
... )
Value:

◆ FATAL_FIRST

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

◆ FATAL_FIRST_

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

◆ FATAL_IF

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

◆ FATAL_IF_EVERY_

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

◆ INFO

#define INFO ( ...)
Value:
ZEROERR_INFO(__VA_ARGS__)
#define ZEROERR_INFO(...)
Definition log.h:35

◆ INFO_EVERY_

#define INFO_EVERY_ ( n,
... )
Value:

◆ INFO_FIRST

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

◆ INFO_FIRST_

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

◆ INFO_IF

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

◆ INFO_IF_EVERY_

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

◆ LOG

#define LOG ( ...)
Value:
ZEROERR_LOG(__VA_ARGS__)
#define ZEROERR_LOG(...)
Definition log.h:36

◆ LOG_EVERY_

#define LOG_EVERY_ ( n,
... )
Value:

◆ LOG_FIRST

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

◆ LOG_FIRST_

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

◆ LOG_GET

#define LOG_GET ( func,
id,
name,
type )
Value:
ZEROERR_LOG_GET(func, id, name, type)
#define ZEROERR_LOG_GET(func, id, name, type)
Definition log.h:214

◆ LOG_IF

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

◆ LOG_IF_EVERY_

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

◆ VERBOSE

#define VERBOSE ( v)
Value:
#define ZEROERR_VERBOSE(v)
Definition log.h:166

◆ WARN

#define WARN ( ...)
Value:
ZEROERR_WARN(__VA_ARGS__)
#define ZEROERR_WARN(...)
Definition log.h:37

◆ WARN_EVERY_

#define WARN_EVERY_ ( n,
... )
Value:

◆ WARN_FIRST

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

◆ WARN_FIRST_

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

◆ WARN_IF

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

◆ WARN_IF_EVERY_

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

◆ ZEROERR_ERROR

#define ZEROERR_ERROR ( ...)
Value:
#define ZEROERR_SUPPRESS_VARIADIC_MACRO_POP
Definition config.h:316
#define ZEROERR_EXPAND(x)
Definition config.h:131
#define ZEROERR_SUPPRESS_VARIADIC_MACRO
Definition config.h:312
#define ZEROERR_LOG_(severity, message,...)
Definition log.h:168

◆ ZEROERR_FATAL

#define ZEROERR_FATAL ( ...)

◆ ZEROERR_G_CONTEXT_SCOPE

#define ZEROERR_G_CONTEXT_SCOPE ( x)
Value:
if (x) { \
for (auto* zeroerr_context_scope : zeroerr::_ZEROERR_G_CONTEXT_SCOPE_VECTOR) { \
zeroerr_context_scope->str(zeroerr::getStderrPrinter().os); \
} \
}
std::vector< IContextScope * > _ZEROERR_G_CONTEXT_SCOPE_VECTOR
Definition log.cpp:27
Printer & getStderrPrinter()
Definition print.cpp:14

◆ ZEROERR_INFO

#define ZEROERR_INFO ( ...)
Value:

◆ ZEROERR_INFO_

#define ZEROERR_INFO_ ( ...)
Value:
ZEROERR_INFO_IMPL(ZEROERR_NAMEGEN(_capture_), ZEROERR_NAMEGEN(_capture_), __VA_ARGS__)
#define ZEROERR_NAMEGEN(x)
Definition config.h:110
#define ZEROERR_INFO_IMPL(mb_name, v_name,...)
Definition log.h:187

◆ ZEROERR_INFO_IMPL

#define ZEROERR_INFO_IMPL ( mb_name,
v_name,
... )
Value:
auto v_name = zeroerr::MakeContextScope([&](zeroerr::StringBuffer& _capture_name) { \
zeroerr::Printer print(_capture_name); \
print.isQuoted = false; \
print(__VA_ARGS__); \
})
Definition buffer.h:7
ContextScope< F > MakeContextScope(const F &f)
Helper function to create a context scope.
Definition log.h:713
A functor class Printer for printing a value of any type.
Definition print.h:87

◆ ZEROERR_LOG

◆ ZEROERR_LOG_

#define ZEROERR_LOG_ ( severity,
message,
... )
Value:
do { \
ZEROERR_G_CONTEXT_SCOPE(true); \
auto msg = zeroerr::makeLogRecord(__VA_ARGS__); \
\
static zeroerr::LogInfo log_info{__FILE__, \
__func__, \
message, \
__LINE__, \
sizeof(msg.entry), \
zeroerr::LogSeverity::severity}; \
msg.entry.info = &log_info; \
msg.stream.write(std::move(msg.entry)); \
} while (0)
const char * ZEROERR_LOG_CATEGORY
Definition log.cpp:20
LogRecord< T... > makeLogRecord(LogStream &stream, T &&... args)
Definition log.h:652
LogInfo is a struct to store the meta data of the log message.
Definition log.h:266

◆ ZEROERR_LOG_EVERY_

#define ZEROERR_LOG_EVERY_ ( n,
ACTION,
... )
Value:
do { \
static 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 { \
static 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 { \
static unsigned counter = n; \
if (counter && (cond)) { \
counter--; \
ACTION(__VA_ARGS__); \
} \
} while (0)

◆ ZEROERR_LOG_GET

#define ZEROERR_LOG_GET ( func,
id,
name,
type )
Value:
zeroerr::LogStream::getDefault().getLog<type>(#func, id, #name)
T getLog(zeroerr::String func, unsigned line, zeroerr::String name)
get a log message from the stream
Definition log.h:565
static LogStream & getDefault()
Definition log.cpp:399

◆ 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 { \
if (cond) { \
static unsigned counter = 0; \
if (counter == 0) { \
counter = n; \
ACTION(__VA_ARGS__); \
} \
--counter; \
} \
} while (0)

◆ ZEROERR_PRINT_ASSERT_DEFAULT_PRINTER

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

◆ ZEROERR_VERBOSE

#define ZEROERR_VERBOSE ( v)
Value:
int _ZEROERR_G_VERBOSE
Definition log.cpp:25

◆ ZEROERR_WARN

Variable Documentation

◆ ZEROERR_LOG_CATEGORY

ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH const char* ZEROERR_LOG_CATEGORY
extern