RyanMqttLog.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef __RyanMqttLog__
  2. #define __RyanMqttLog__
  3. #include <stdint.h>
  4. #include <stdarg.h>
  5. // 日志等级
  6. #define RyanMqttLogLevelAssert 0
  7. #define RyanMqttLogLevelError 1
  8. #define RyanMqttLogLevelWarning 2
  9. #define RyanMqttLogLevelInfo 3
  10. #define RyanMqttLogLevelDebug 4
  11. // 日志打印等级
  12. #ifndef RyanMqttLogLevel
  13. #define RyanMqttLogLevel (RyanMqttLogLevelDebug)
  14. #endif
  15. extern void RyanMqttLogOutPutRaw(char *const fmt, ...);
  16. extern void RyanMqttLogOutPut(const char *lvl, uint8_t color, const char *fileStr, uint32_t lineNum, char *const fmt,
  17. ...);
  18. /**
  19. * @brief log等级检索
  20. *
  21. */
  22. #if (RyanMqttLogLevel >= RyanMqttLogLevelDebug)
  23. #define RyanMqttLog_d(fmt, ...) RyanMqttLogOutPut("D", 0, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  24. #else
  25. #define RyanMqttLog_d(...)
  26. #endif
  27. #if (RyanMqttLogLevel >= RyanMqttLogLevelInfo)
  28. #define RyanMqttLog_i(fmt, ...) RyanMqttLogOutPut("I", 32, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  29. #else
  30. #define RyanMqttLog_i(...)
  31. #endif
  32. #if (RyanMqttLogLevel >= RyanMqttLogLevelWarning)
  33. #define RyanMqttLog_w(fmt, ...) RyanMqttLogOutPut("W", 33, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  34. #else
  35. #define RyanMqttLog_w(...)
  36. #endif
  37. #if (RyanMqttLogLevel >= RyanMqttLogLevelError)
  38. #define RyanMqttLog_e(fmt, ...) RyanMqttLogOutPut("E", 31, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  39. #else
  40. #define RyanMqttLog_e(...)
  41. #endif
  42. #define RyanMqttLog_raw(...) RyanMqttLogOutPutRaw(__VA_ARGS__)
  43. #endif