mqtt_log.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-27 03:25:58
  5. * @LastEditTime: 2020-10-17 14:15:55
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #ifndef _MQTT_LOG_H_
  9. #define _MQTT_LOG_H_
  10. #include "mqtt_defconfig.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define MQTT_LOG_BASE_LEVEL (0)
  15. #define MQTT_LOG_ERR_LEVEL (MQTT_LOG_BASE_LEVEL + 1)
  16. #define MQTT_LOG_WARN_LEVEL (MQTT_LOG_ERR_LEVEL + 1)
  17. #define MQTT_LOG_INFO_LEVEL (MQTT_LOG_WARN_LEVEL + 1)
  18. #define MQTT_LOG_DEBUG_LEVEL (MQTT_LOG_INFO_LEVEL + 1)
  19. #ifdef MQTT_LOG_IS_SALOF
  20. #include "salof.h"
  21. #define MQTT_LOG_D(fmt, ...) SALOF_LOG_DEBUG(fmt, ##__VA_ARGS__)
  22. #define MQTT_LOG_I(fmt, ...) SALOF_LOG_INFO(fmt, ##__VA_ARGS__)
  23. #define MQTT_LOG_W(fmt, ...) SALOF_LOG_WARN(fmt, ##__VA_ARGS__)
  24. #define MQTT_LOG_E(fmt, ...) SALOF_LOG_ERR(fmt, ##__VA_ARGS__)
  25. #define mqtt_log_init salof_init
  26. #else
  27. #include <stdio.h>
  28. #if MQTT_LOG_LEVEL < MQTT_LOG_DEBUG_LEVEL
  29. #define MQTT_LOG_D(fmt, ...)
  30. #else
  31. #define MQTT_LOG_D(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  32. #endif
  33. #if MQTT_LOG_LEVEL < MQTT_LOG_INFO_LEVEL
  34. #define MQTT_LOG_I(fmt, ...)
  35. #else
  36. #define MQTT_LOG_I(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  37. #endif
  38. #if MQTT_LOG_LEVEL < MQTT_LOG_WARN_LEVEL
  39. #define MQTT_LOG_W(fmt, ...)
  40. #else
  41. #define MQTT_LOG_W(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  42. #endif
  43. #if MQTT_LOG_LEVEL < MQTT_LOG_ERR_LEVEL
  44. #define MQTT_LOG_E(fmt, ...)
  45. #else
  46. #define MQTT_LOG_E(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  47. #endif
  48. #if MQTT_LOG_LEVEL < MQTT_LOG_BASE_LEVEL
  49. #define MQTT_LOG(fmt, ...)
  50. #else
  51. #define MQTT_LOG(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  52. #endif
  53. #define mqtt_log_init()
  54. #endif
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif /* _LOG_H_ */