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  TIME = 3,
13  WARN = 4,
14  ERR = 5
15 };
16 
17 struct enum_hasher {
18  template <typename T>
19  std::size_t operator()(T t) const
20  { return static_cast<std::size_t>(t); }
21 };
22 
23 //all, something in between, none or default to info
24 #if defined(LOGGING_LEVEL_ALL) || defined(LOGGING_LEVEL_TRACE)
25 constexpr log_level LOG_LEVEL_CUTOFF = log_level::TRACE;
26 #elif defined(LOGGING_LEVEL_DEBUG)
27 constexpr log_level LOG_LEVEL_CUTOFF = log_level::DEBUG;
28 #elif defined(LOGGING_LEVEL_WARN)
29 constexpr log_level LOG_LEVEL_CUTOFF = log_level::WARN;
30 #elif defined(LOGGING_LEVEL_ERROR)
31 constexpr log_level LOG_LEVEL_CUTOFF = log_level::ERR;
32 #elif defined(LOGGING_LEVEL_NONE)
33 constexpr log_level LOG_LEVEL_CUTOFF = log_level::ERR + 1;
34 #else
35 constexpr log_level LOG_LEVEL_CUTOFF = log_level::INFO;
36 #endif
37 
41 const std::unordered_map<log_level, std::string, enum_hasher> uncolored{
42  {log_level::ERR, " [ERROR] "},
43  {log_level::WARN, " [WARN] "},
44  {log_level::INFO, " [INFO] "},
45  {log_level::TIME, " [TIME] "},
46  {log_level::DEBUG, " [DEBUG] "},
47  {log_level::TRACE, " [TRACE] "}
48 };
49 
53 const std::unordered_map<log_level, std::string, enum_hasher> colored{
54  {log_level::ERR, " \x1b[31;1m[ERROR]\x1b[0m "},
55  {log_level::WARN, " \x1b[33;1m[WARN]\x1b[0m "},
56  {log_level::INFO, " \x1b[32;1m[INFO]\x1b[0m "},
57  {log_level::TIME, " \x1b[36;1m[TIME]\x1b[0m "},
58  {log_level::DEBUG, " \x1b[34;1m[DEBUG]\x1b[0m "},
59  {log_level::TRACE, " \x1b[37;1m[TRACE]\x1b[0m "}
60 };
61 
62 //logger base class, not pure virtual so you can use as a null logger
63 using logging_config_t = std::unordered_map<std::string, std::string>;
void INFO(const std::string &message)
Default info messages logging function.
Definition: logging.hpp:232
void ERR(const std::string &message)
Default error messages logging function.
Definition: logging.hpp:256
void TIME(const std::string &message)
Default time messages loggin function.
Definition: logging.hpp:240
void TRACE(const std::string &message)
Default trace messages logging function.
Definition: logging.hpp:216
void WARN(const std::string &message)
Default warning messages logging function.
Definition: logging.hpp:248
void DEBUG(const std::string &message)
Default debug messages logging function.
Definition: logging.hpp:224
Definition: logging_common.hpp:17