Helios++
Helios software for LiDAR simulations
logging_common.hpp
1 #pragma once
2 
3 //TODO: use macros (again) so __FILE__ __LINE__ could be automatically added to certain error levels?
4 //the log levels we support
8 enum class log_level : uint8_t{
9  TRACE = 0,
10  DEBUG = 1,
11  INFO = 2,
12  WARN = 3,
13  ERR = 4
14 };
15 
16 struct enum_hasher {
17  template <typename T>
18  std::size_t operator()(T t) const
19  { return static_cast<std::size_t>(t); }
20 };
21 
22 //all, something in between, none or default to info
23 #if defined(LOGGING_LEVEL_ALL) || defined(LOGGING_LEVEL_TRACE)
24 constexpr log_level LOG_LEVEL_CUTOFF = log_level::TRACE;
25 #elif defined(LOGGING_LEVEL_DEBUG)
26 constexpr log_level LOG_LEVEL_CUTOFF = log_level::DEBUG;
27 #elif defined(LOGGING_LEVEL_WARN)
28 constexpr log_level LOG_LEVEL_CUTOFF = log_level::WARN;
29 #elif defined(LOGGING_LEVEL_ERROR)
30 constexpr log_level LOG_LEVEL_CUTOFF = log_level::ERR;
31 #elif defined(LOGGING_LEVEL_NONE)
32 constexpr log_level LOG_LEVEL_CUTOFF = log_level::ERR + 1;
33 #else
34 constexpr log_level LOG_LEVEL_CUTOFF = log_level::INFO;
35 #endif
36 
40 const std::unordered_map<log_level, std::string, enum_hasher> uncolored{
41  {log_level::ERR, " [ERROR] "},
42  {log_level::WARN, " [WARN] "},
43  {log_level::INFO, " [INFO] "},
44  {log_level::DEBUG, " [DEBUG] "},
45  {log_level::TRACE, " [TRACE] "}
46 };
47 
51 const std::unordered_map<log_level, std::string, enum_hasher> colored{
52  {log_level::ERR, " \x1b[31;1m[ERROR]\x1b[0m "},
53  {log_level::WARN, " \x1b[33;1m[WARN]\x1b[0m "},
54  {log_level::INFO, " \x1b[32;1m[INFO]\x1b[0m "},
55  {log_level::DEBUG, " \x1b[34;1m[DEBUG]\x1b[0m "},
56  {log_level::TRACE, " \x1b[37;1m[TRACE]\x1b[0m "}
57 };
58 
59 //logger base class, not pure virtual so you can use as a null logger
60 using logging_config_t = std::unordered_map<std::string, std::string>;
void DEBUG(const std::string &message)
Default debug messages logging function.
Definition: logging.hpp:205
void WARN(const std::string &message)
Default warning messages logging function.
Definition: logging.hpp:221
void ERR(const std::string &message)
Default error messages logging function.
Definition: logging.hpp:229
void INFO(const std::string &message)
Default info messages logging function.
Definition: logging.hpp:213
Definition: logging_common.hpp:16
void TRACE(const std::string &message)
Default trace messages logging function.
Definition: logging.hpp:197