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. #include "log.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define MQTT_LOG_BASE_LEVEL (0)
  16. #define MQTT_LOG_ERR_LEVEL (MQTT_LOG_BASE_LEVEL + 1)
  17. #define MQTT_LOG_WARN_LEVEL (MQTT_LOG_ERR_LEVEL + 1)
  18. #define MQTT_LOG_INFO_LEVEL (MQTT_LOG_WARN_LEVEL + 1)
  19. #define MQTT_LOG_DEBUG_LEVEL (MQTT_LOG_INFO_LEVEL + 1)
  20. #ifdef MQTT_LOG_IS_SALOF
  21. #include "salof.h"
  22. #define MQTT_LOG_D(fmt, ...) SALOF_LOG_DEBUG(fmt, ##__VA_ARGS__)
  23. #define MQTT_LOG_I(fmt, ...) SALOF_LOG_INFO(fmt, ##__VA_ARGS__)
  24. #define MQTT_LOG_W(fmt, ...) SALOF_LOG_WARN(fmt, ##__VA_ARGS__)
  25. #define MQTT_LOG_E(fmt, ...) SALOF_LOG_ERR(fmt, ##__VA_ARGS__)
  26. #define mqtt_log_init salof_init
  27. #else
  28. #include <stdio.h>
  29. #if MQTT_LOG_LEVEL < MQTT_LOG_DEBUG_LEVEL
  30. #define MQTT_LOG_D(fmt, ...)
  31. #else
  32. #define MQTT_LOG_D(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  33. #endif
  34. #if MQTT_LOG_LEVEL < MQTT_LOG_INFO_LEVEL
  35. #define MQTT_LOG_I(fmt, ...)
  36. #else
  37. #define MQTT_LOG_I(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  38. #endif
  39. #if MQTT_LOG_LEVEL < MQTT_LOG_WARN_LEVEL
  40. #define MQTT_LOG_W(fmt, ...)
  41. #else
  42. #define MQTT_LOG_W(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  43. #endif
  44. #if MQTT_LOG_LEVEL < MQTT_LOG_ERR_LEVEL
  45. #define MQTT_LOG_E(fmt, ...)
  46. #else
  47. #define MQTT_LOG_E(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  48. #endif
  49. #if MQTT_LOG_LEVEL < MQTT_LOG_BASE_LEVEL
  50. #define MQTT_LOG(fmt, ...)
  51. #else
  52. #define MQTT_LOG(fmt, ...) { printf(fmt, ##__VA_ARGS__); printf("\n");}
  53. #endif
  54. #define mqtt_log_init()
  55. #endif
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* _LOG_H_ */