RyanMqttLog.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef __RyanMqttLog__
  2. #define __RyanMqttLog__
  3. #include <stdio.h>
  4. #include <stdarg.h>
  5. #include "platformSystem.h"
  6. // 日志等级
  7. #define rlogLvlAssert 0
  8. #define rlogLvlError 1
  9. #define rlogLvlWarning 2
  10. #define rlogLvlInfo 2
  11. #define rlogLvlDebug 3
  12. // 日志打印等级
  13. #ifndef rlogLevel
  14. #define rlogLevel (rlogLvlDebug)
  15. #endif
  16. // 日志tag
  17. #ifndef rlogTag
  18. #define rlogTag "LOG"
  19. #endif
  20. extern void rlog_output_raw(char *const fmt, ...);
  21. extern void rlog_output(char *lvl, uint8_t color_n, char *fileStr, uint32_t lineNum, char *const fmt, ...);
  22. /**
  23. * @brief log等级检索
  24. *
  25. */
  26. #if (rlogLevel >= rlogLvlDebug)
  27. #define rlog_d(fmt, ...) rlog_output("D", 0, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  28. #else
  29. #define rlog_d(...)
  30. #endif
  31. #if (rlogLevel >= rlogLvlInfo)
  32. #define rlog_i(fmt, ...) rlog_output("I", 32, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  33. #else
  34. #define rlog_i(...)
  35. #endif
  36. #if (rlogLevel >= rlogLvlWarning)
  37. #define rlog_w(fmt, ...) rlog_output("W", 33, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  38. #else
  39. #define rlog_w(...)
  40. #endif
  41. #if (rlogLevel >= rlogLvlError)
  42. #define rlog_e(fmt, ...) rlog_output("E", 31, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  43. #else
  44. #define rlog_e(...)
  45. #endif
  46. #define rlog_raw(...) rlog_output_raw(__VA_ARGS__)
  47. #endif