Leosac  0.7.0
OpenSourceAccessControl
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__
 Macro used to get the name of the function that called the logging macro. More...
 
#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 NOTICE_0(msg)
 See "Internal macros documentation". More...
 
#define NOTICE_1(msg, loggers)
 See "Internal macros documentation". More...
 
#define NOTICE_X(trash, msg, loggers, targetMacro, ...)   targetMacro
 See "Internal macros documentation". More...
 
#define NOTICE(...)
 Notice 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 {
  EMERG = spdlog::level::emerg, ALERT = spdlog::level::alert, CRIT = spdlog::level::critical, ERROR = spdlog::level::err,
  WARN = spdlog::level::warn, NOTICE = spdlog::level::notice, 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)
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58

Definition at line 221 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 66 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__), )
#define DEBUG_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:91
#define DEBUG_0(msg)
See "Internal macros documentation".
Definition: log.hpp:77
#define DEBUG_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:84

Debug macro.

Issue a log message with DEBUG level

Definition at line 97 of file log.hpp.

◆ DEBUG_0

#define DEBUG_0 (   msg)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47
#define DEBUG(...)
Debug macro.
Definition: log.hpp:97

See "Internal macros documentation".

Definition at line 77 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)
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47
#define DEBUG(...)
Debug macro.
Definition: log.hpp:97

See "Internal macros documentation".

Definition at line 84 of file log.hpp.

◆ DEBUG_X

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

See "Internal macros documentation".

Definition at line 91 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__), )
#define ERROR_0(msg)
See "Internal macros documentation".
Definition: log.hpp:189
#define ERROR_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:203
#define ERROR_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:196

Error macro.

Issue a log message with ERROR level

Definition at line 209 of file log.hpp.

◆ ERROR_0

#define ERROR_0 (   msg)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
#define ERROR(...)
Error macro.
Definition: log.hpp:209
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 189 of file log.hpp.

◆ ERROR_1

#define ERROR_1 (   msg,
  loggers 
)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
#define ERROR(...)
Error macro.
Definition: log.hpp:209
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 196 of file log.hpp.

◆ ERROR_X

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

See "Internal macros documentation".

Definition at line 203 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 58 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__), )
#define INFO_0(msg)
See "Internal macros documentation".
Definition: log.hpp:105
#define INFO_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:119
#define INFO_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:112

Information macro.

Issue a log message with INFO level.

Definition at line 125 of file log.hpp.

◆ INFO_0

#define INFO_0 (   msg)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
#define INFO(...)
Information macro.
Definition: log.hpp:125
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 105 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)
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
#define INFO(...)
Information macro.
Definition: log.hpp:125
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 112 of file log.hpp.

◆ INFO_X

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

See "Internal macros documentation".

Definition at line 119 of file log.hpp.

◆ NOTICE

#define NOTICE (   ...)
Value:
NOTICE_X(, ##__VA_ARGS__, NOTICE_1(__VA_ARGS__), NOTICE_0(__VA_ARGS__), \
NOTICE_NO_PARAM(__VA_ARGS__), )
#define NOTICE_0(msg)
See "Internal macros documentation".
Definition: log.hpp:133
#define NOTICE_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:147
#define NOTICE_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:140

Notice macro.

Issue a log message with NOTICE level.

Definition at line 153 of file log.hpp.

◆ NOTICE_0

#define NOTICE_0 (   msg)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define NOTICE(...)
Notice macro.
Definition: log.hpp:153
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 133 of file log.hpp.

◆ NOTICE_1

#define NOTICE_1 (   msg,
  loggers 
)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
LogLevel::NOTICE, loggers)
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define NOTICE(...)
Notice macro.
Definition: log.hpp:153
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 140 of file log.hpp.

◆ NOTICE_X

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

See "Internal macros documentation".

Definition at line 147 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__), )
#define WARN_1(msg, loggers)
See "Internal macros documentation".
Definition: log.hpp:168
#define WARN_0(msg)
See "Internal macros documentation".
Definition: log.hpp:161
#define WARN_X(trash, msg, loggers, targetMacro,...)
See "Internal macros documentation".
Definition: log.hpp:175

Warning macro.

Issue a log message with WARN level.

Definition at line 181 of file log.hpp.

◆ WARN_0

#define WARN_0 (   msg)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define WARN(...)
Warning macro.
Definition: log.hpp:181
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 161 of file log.hpp.

◆ WARN_1

#define WARN_1 (   msg,
  loggers 
)
Value:
LogHelper::log(BUILD_STR(msg), __LINE__, FUNCTION_NAME_MACRO, __FILE__, \
#define WARN(...)
Warning macro.
Definition: log.hpp:181
#define FUNCTION_NAME_MACRO
Macro used to get the name of the function that called the logging macro.
Definition: log.hpp:58
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:66
void log(const std::string &log_msg, int, const char *, const char *, LogLevel level)
Definition: log.cpp:47

See "Internal macros documentation".

Definition at line 168 of file log.hpp.

◆ WARN_X

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

See "Internal macros documentation".

Definition at line 175 of file log.hpp.

Enumeration Type Documentation

◆ LogLevel

enum LogLevel
Enumerator
EMERG 
ALERT 
CRIT 
ERROR 
WARN 
NOTICE 
INFO 
DEBUG 

Definition at line 29 of file log.hpp.