SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
linux/spsp/logger.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <cstdint>
13 #include <cstdio>
14 
15 namespace SPSP
16 {
17  enum class LogLevel : uint_fast8_t
18  {
19  DEBUG = 0,
20  INFO = 1,
21  WARN = 2,
22  ERROR = 3,
23  OFF = 255,
24  };
25 
27  extern LogLevel logLevel;
28 } // namespace SPSP
29 
30 #define _SPSP_LOG(level, levelLogStrPre, levelLogStrPost, fmt, ...) \
31  do { \
32  if (SPSP::logLevel <= SPSP::LogLevel::level) { \
33  fprintf(stderr, levelLogStrPre " %s: " fmt "\n" levelLogStrPost, \
34  SPSP_LOG_TAG, ##__VA_ARGS__); \
35  } \
36  } while (0)
37 
38 #if SPSP_LOG_NO_COLORS
39  #define SPSP_LOGD(fmt, ...) _SPSP_LOG(DEBUG, "[D]", "", fmt, ##__VA_ARGS__)
40  #define SPSP_LOGI(fmt, ...) _SPSP_LOG(INFO, "[I]", "", fmt, ##__VA_ARGS__)
41  #define SPSP_LOGW(fmt, ...) _SPSP_LOG(WARN, "[W]", "", fmt, ##__VA_ARGS__)
42  #define SPSP_LOGE(fmt, ...) _SPSP_LOG(ERROR, "[E]", "", fmt, ##__VA_ARGS__)
43 #else
44  #define SPSP_LOGD(fmt, ...) _SPSP_LOG(DEBUG, "\033[0;34m[D]", "\033[0m", fmt, ##__VA_ARGS__)
45  #define SPSP_LOGI(fmt, ...) _SPSP_LOG(INFO, "\033[0;36m[I]", "\033[0m", fmt, ##__VA_ARGS__)
46  #define SPSP_LOGW(fmt, ...) _SPSP_LOG(WARN, "\033[0;33m[W]", "\033[0m", fmt, ##__VA_ARGS__)
47  #define SPSP_LOGE(fmt, ...) _SPSP_LOG(ERROR, "\033[0;31m[E]", "\033[0m", fmt, ##__VA_ARGS__)
48 #endif
SPSP::logLevel
LogLevel logLevel
Global log level.