Leosac  0.8.0
Open Source Access Control
log.hpp File Reference
#include <cassert>
#include <csignal>
#include <iostream>
#include <spdlog/spdlog.h>
#include <sstream>
#include <string>
+ Include dependency graph for log.hpp:

Go to the source code of this file.

Namespaces

 LogHelper
 

Macros

#define FUNCTION_NAME_MACRO   __FUNCTION__
 
#define BUILD_STR(param)
 Internal macro. More...
 
#define DEBUG_0(msg)
 See "Internal macros documentation". More...
 
#define DEBUG_1(msg, loggers)
 See "Internal macros documentation". More...
 
#define DEBUG_X(trash, msg, loggers, targetMacro, ...)   targetMacro
 See "Internal macros documentation". More...
 
#define DEBUG(...)
 Debug macro. More...
 
#define INFO_0(msg)
 See "Internal macros documentation". More...
 
#define INFO_1(msg, loggers)
 See "Internal macros documentation". More...
 
#define INFO_X(trash, msg, loggers, targetMacro, ...)   targetMacro
 See "Internal macros documentation". More...
 
#define INFO(...)
 Information macro. More...
 
#define WARN_0(msg)
 See "Internal macros documentation". More...
 
#define WARN_1(msg, loggers)
 See "Internal macros documentation". More...
 
#define WARN_X(trash, msg, loggers, targetMacro, ...)   targetMacro
 See "Internal macros documentation". More...
 
#define WARN(...)
 Warning macro. More...
 
#define ERROR_0(msg)
 See "Internal macros documentation". More...
 
#define ERROR_1(msg, loggers)
 See "Internal macros documentation". More...
 
#define ERROR_X(trash, msg, loggers, targetMacro, ...)   targetMacro
 See "Internal macros documentation". More...
 
#define ERROR(...)
 Error macro. More...
 
#define ASSERT_LOG(cond, msg)
 

Enumerations

enum  LogLevel {
  CRIT = spdlog::level::critical, ERROR = spdlog::level::err, WARN = spdlog::level::warn, INFO = spdlog::level::info,
  DEBUG = spdlog::level::debug
}
 

Functions

LogLevel LogHelper::log_level_from_string (const std::string &level)
 
void LogHelper::log (const std::string &log_msg, int, const char *, const char *, LogLevel level)
 

Macro Definition Documentation

◆ ASSERT_LOG

#define ASSERT_LOG (   cond,
  msg 
)
Value:
do \
{ \
if (!(cond)) \
{ \
ERROR(msg); \
ERROR("Assertion failed in " << __FILE__ << " --> " \
<< FUNCTION_NAME_MACRO << ":" << __LINE__ \
<< ". Aborting."); \
raise(SIGABRT); \
} \
} while (false)

Definition at line 190 of file log.hpp.

◆ BUILD_STR

#define BUILD_STR (   param)
Value:
[&](void) { \
std::stringstream logger_macro_ss__; \
logger_macro_ss__ << param; \
return logger_macro_ss__.str(); \
}()

Internal macro.

It is used to create an anonymous lambda to allow the logging macros parameter to behave like a stringstream.

Definition at line 63 of file log.hpp.

◆ DEBUG

#define DEBUG (   ...)
Value:
DEBUG_X(, ##__VA_ARGS__, DEBUG_1(__VA_ARGS__), DEBUG_0(__VA_ARGS__), \
DEBUG_NO_PARAM(__VA_ARGS__), )

Debug macro.

Issue a log message with DEBUG level

Definition at line 94 of file log.hpp.

◆ DEBUG_0

#define DEBUG_0 (   msg)
Value:

See "Internal macros documentation".

Definition at line 74 of file log.hpp.

◆ DEBUG_1

#define DEBUG_1 (   msg,
  loggers 
)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
LogLevel::DEBUG, loggers)

See "Internal macros documentation".

Definition at line 81 of file log.hpp.

◆ DEBUG_X

#define DEBUG_X (   trash,
  msg,
  loggers,
  targetMacro,
  ... 
)    targetMacro

See "Internal macros documentation".

Definition at line 88 of file log.hpp.

◆ ERROR

#define ERROR (   ...)
Value:
ERROR_X(, ##__VA_ARGS__, ERROR_1(__VA_ARGS__), ERROR_0(__VA_ARGS__), \
ERROR_NO_PARAM(__VA_ARGS__), )

Error macro.

Issue a log message with ERROR level

Definition at line 178 of file log.hpp.

◆ ERROR_0

#define ERROR_0 (   msg)
Value:

See "Internal macros documentation".

Definition at line 158 of file log.hpp.

◆ ERROR_1

#define ERROR_1 (   msg,
  loggers 
)
Value:

See "Internal macros documentation".

Definition at line 165 of file log.hpp.

◆ ERROR_X

#define ERROR_X (   trash,
  msg,
  loggers,
  targetMacro,
  ... 
)    targetMacro

See "Internal macros documentation".

Definition at line 172 of file log.hpp.

◆ FUNCTION_NAME_MACRO

#define FUNCTION_NAME_MACRO   __FUNCTION__

Macro used to get the name of the function that called the logging macro. GNU compilers provide a nice macro the get a more detailed name of a function. Otherwise we fallback to a more widespread macro.

Definition at line 55 of file log.hpp.

◆ INFO

#define INFO (   ...)
Value:
INFO_X(, ##__VA_ARGS__, INFO_1(__VA_ARGS__), INFO_0(__VA_ARGS__), \
INFO_NO_PARAM(__VA_ARGS__), )

Information macro.

Issue a log message with INFO level.

Definition at line 122 of file log.hpp.

◆ INFO_0

#define INFO_0 (   msg)
Value:

See "Internal macros documentation".

Definition at line 102 of file log.hpp.

◆ INFO_1

#define INFO_1 (   msg,
  loggers 
)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
LogLevel::INFO, loggers)

See "Internal macros documentation".

Definition at line 109 of file log.hpp.

◆ INFO_X

#define INFO_X (   trash,
  msg,
  loggers,
  targetMacro,
  ... 
)    targetMacro

See "Internal macros documentation".

Definition at line 116 of file log.hpp.

◆ WARN

#define WARN (   ...)
Value:
WARN_X(, ##__VA_ARGS__, WARN_1(__VA_ARGS__), WARN_0(__VA_ARGS__), \
WARN_NO_PARAM(__VA_ARGS__), )

Warning macro.

Issue a log message with WARN level.

Definition at line 150 of file log.hpp.

◆ WARN_0

#define WARN_0 (   msg)
Value:

See "Internal macros documentation".

Definition at line 130 of file log.hpp.

◆ WARN_1

#define WARN_1 (   msg,
  loggers 
)
Value:

See "Internal macros documentation".

Definition at line 137 of file log.hpp.

◆ WARN_X

#define WARN_X (   trash,
  msg,
  loggers,
  targetMacro,
  ... 
)    targetMacro

See "Internal macros documentation".

Definition at line 144 of file log.hpp.

Enumeration Type Documentation

◆ LogLevel

enum LogLevel
Enumerator
CRIT 
ERROR 
WARN 
INFO 
DEBUG 

Definition at line 29 of file log.hpp.

INFO
#define INFO(...)
Information macro.
Definition: log.hpp:122
BUILD_STR
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:63
ERROR_0
#define ERROR_0(msg)
See "Internal macros documentation".
Definition: log.hpp:158
WARN_X
#define WARN_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:144
DEBUG_1
#define DEBUG_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:81
FUNCTION_NAME_MACRO
#define FUNCTION_NAME_MACRO
Definition: log.hpp:55
DEBUG_X
#define DEBUG_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:88
INFO_1
#define INFO_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:109
ERROR_1
#define ERROR_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:165
ERROR
#define ERROR(...)
Error macro.
Definition: log.hpp:178
WARN_1
#define WARN_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:137
WARN
#define WARN(...)
Warning macro.
Definition: log.hpp:150
ERROR_X
#define ERROR_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:172
DEBUG_0
#define DEBUG_0(msg)
See "Internal macros documentation".
Definition: log.hpp:74
INFO_X
#define INFO_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:116
DEBUG
#define DEBUG(...)
Debug macro.
Definition: log.hpp:94
INFO_0
#define INFO_0(msg)
See "Internal macros documentation".
Definition: log.hpp:102
LogHelper::log
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47
WARN_0
#define WARN_0(msg)
See "Internal macros documentation".
Definition: log.hpp:130