salof.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _SALOF_H_
  2. #define _SALOF_H_
  3. #include "salof_defconfig.h"
  4. #include "format.h"
  5. #include "fifo.h"
  6. #include <stdio.h>
  7. int salof_init(void);
  8. void salof(const char *fmt, ...);
  9. /** font color */
  10. #define SALOF_FC_BLACK 30
  11. #define SALOF_FC_RED 31
  12. #define SALOF_FC_GREEN 32
  13. #define SALOF_FC_YELLOW 33
  14. #define SALOF_FC_BLUE 34
  15. #define SALOF_FC_PURPLE 35
  16. #define SALOF_FC_DARK 36
  17. #define SALOF_FC_WHITE 37
  18. #ifdef SALOF_USING_LOG
  19. #if SALOF_USING_SALOF
  20. #define SALOF_PRINT_LOG salof
  21. #else
  22. #if ((!SALOF_USING_SALOF)&&(!SALOF_PRINT_LOG))
  23. #define SALOF_PRINT_LOG printf
  24. #endif
  25. #ifndef SALOF_PRINT_LOG
  26. #error "If the SALOF_USING_LOG macro definition is turned on, you must define SALOF_PRINT_LOG as the LOG output, such as #definePRINT_LOG printf"
  27. #endif
  28. #endif
  29. #if SALOF_LOG_COLOR
  30. #define SALOF_LOG_START(l, c) SALOF_PRINT_LOG("\033\n["#c"m["#l"] >> ")
  31. #define SALOF_LOG_END SALOF_PRINT_LOG("\033[0m")
  32. #else
  33. #define SALOF_LOG_START(l, c) SALOF_PRINT_LOG("\n["#l"] >> ")
  34. #define SALOF_LOG_END
  35. #endif
  36. #if SALOF_LOG_TS && SALOF_LOG_TAR
  37. #define SALOF_LOG_T SALOF_PRINT_LOG("[TS: %d] [TAR: %s] ",salof_get_tick(), salof_get_task_name())
  38. #elif SALOF_LOG_TS
  39. #define SALOF_LOG_T SALOF_PRINT_LOG("[TS: %d] ", salof_get_tick())
  40. #elif SALOF_LOG_TAR
  41. #define SALOF_LOG_T SALOF_PRINT_LOG("[TAR: %s] ", salof_get_task_name())
  42. #else
  43. #define SALOF_LOG_T
  44. #endif
  45. #define SALOF_LOG_LINE(l, c, fmt, ...) \
  46. do { \
  47. SALOF_LOG_START(l, c); \
  48. SALOF_LOG_T; \
  49. SALOF_PRINT_LOG(fmt, ##__VA_ARGS__); \
  50. SALOF_LOG_END; \
  51. } while (0)
  52. #define SALOF_BASE_LEVEL (0)
  53. #define SALOF_ERR_LEVEL (SALOF_BASE_LEVEL + 1)
  54. #define SALOF_WARN_LEVEL (SALOF_ERR_LEVEL + 1)
  55. #define SALOF_INFO_LEVEL (SALOF_WARN_LEVEL + 1)
  56. #define SALOF_DEBUG_LEVEL (SALOF_INFO_LEVEL + 1)
  57. #ifndef SALOF_LOG_LEVEL
  58. #define SALOF_LOG_LEVEL SALOF_DEBUG_LEVEL
  59. #endif
  60. #if SALOF_LOG_LEVEL < SALOF_DEBUG_LEVEL
  61. #define SALOF_LOG_DEBUG(fmt, ...)
  62. #else
  63. #define SALOF_LOG_DEBUG(fmt, ...) SALOF_LOG_LINE(D, 0, fmt, ##__VA_ARGS__)
  64. #endif
  65. #if SALOF_LOG_LEVEL < SALOF_INFO_LEVEL
  66. #define SALOF_LOG_INFO(fmt, ...)
  67. #else
  68. #define SALOF_LOG_INFO(fmt, ...) SALOF_LOG_LINE(I, SALOF_FC_GREEN, fmt, ##__VA_ARGS__)
  69. #endif
  70. #if SALOF_LOG_LEVEL < SALOF_WARN_LEVEL
  71. #define SALOF_LOG_WARN(fmt, ...)
  72. #else
  73. #define SALOF_LOG_WARN(fmt, ...) SALOF_LOG_LINE(W, SALOF_FC_YELLOW, fmt, ##__VA_ARGS__)
  74. #endif
  75. #if SALOF_LOG_LEVEL < SALOF_ERR_LEVEL
  76. #define SALOF_LOG_ERR(fmt, ...)
  77. #else
  78. #define SALOF_LOG_ERR(fmt, ...) SALOF_LOG_LINE(E, SALOF_FC_RED, fmt, ##__VA_ARGS__)
  79. #endif
  80. #if SALOF_LOG_LEVEL < SALOF_BASE_LEVEL
  81. #define SALOF_LOG(fmt, ...)
  82. #else
  83. #define SALOF_LOG(fmt, ...) SALOF_PRINT_LOG(fmt, ##__VA_ARGS__)
  84. #endif
  85. #else
  86. #define SALOF_LOG_DEBUG(fmt, ...)
  87. #define SALOF_LOG_INFO(fmt, ...)
  88. #define SALOF_LOG_WARN(fmt, ...)
  89. #define SALOF_LOG_ERR(fmt, ...)
  90. #define SALOF_LOG_LOG(fmt, ...)
  91. #endif
  92. #endif // !_SALOF_H_