ulog.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _ULOG_H_
  2. #define _ULOG_H_
  3. #include <stdarg.h>
  4. #include <FreeRTOS.h>
  5. #include "list.h"
  6. #include "board.h"
  7. #include "ulog_def.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define ULOG_VERSION_STR "0.1.1"
  12. /*
  13. * ulog init and deint
  14. */
  15. int ulog_init(void);
  16. void ulog_deinit(void);
  17. /*
  18. * output different level log by LOG_X API
  19. *
  20. * NOTE: The `LOG_TAG` and `LOG_LVL` must be defined before including the <ulog.h> when you want to use LOG_X API.
  21. *
  22. * #define LOG_TAG "example"
  23. * #define LOG_LVL LOG_LVL_DBG
  24. * #include <ulog.h>
  25. *
  26. * Then you can using LOG_X API to output log
  27. *
  28. * TRACE_DEBUG("this is a debug log!");
  29. * TRACE_ERROR("this is a error log!");
  30. */
  31. #define TRACE_FATAL(...) ulog_f(LOG_TAG, __VA_ARGS__)
  32. #define TRACE_ERROR(...) ulog_e(LOG_TAG, __VA_ARGS__)
  33. #define TRACE_WARNING(...) ulog_w(LOG_TAG, __VA_ARGS__)
  34. #define TRACE_INFO(...) ulog_i(LOG_TAG, __VA_ARGS__)
  35. #define TRACE_DEBUG(...) ulog_d(LOG_TAG, __VA_ARGS__)
  36. #define LOG_RAW(...) ulog_raw(__VA_ARGS__)
  37. #define LOG_HEX(name, width, buf, size) ulog_hex(name, width, buf, size)
  38. /*
  39. * backend register and unregister
  40. */
  41. int ulog_backend_register(ulog_backend_t backend, const char *name, int support_color);
  42. int ulog_backend_unregister(ulog_backend_t backend);
  43. #ifdef ULOG_USING_FILTER
  44. /*
  45. * log filter setting
  46. */
  47. int ulog_tag_lvl_filter_set(const char *tag, uint32_t level);
  48. uint32_t ulog_tag_lvl_filter_get(const char *tag);
  49. List_t *ulog_tag_lvl_list_get(void);
  50. void ulog_global_filter_lvl_set(uint32_t level);
  51. uint32_t ulog_global_filter_lvl_get(void);
  52. void ulog_global_filter_tag_set(const char *tag);
  53. const char *ulog_global_filter_tag_get(void);
  54. void ulog_global_filter_kw_set(const char *keyword);
  55. const char *ulog_global_filter_kw_get(void);
  56. #endif /* ULOG_USING_FILTER */
  57. /*
  58. * flush all backends's log
  59. */
  60. void ulog_flush(void);
  61. #ifdef ULOG_USING_ASYNC_OUTPUT
  62. /*
  63. * asynchronous output API
  64. */
  65. void ulog_async_output(void);
  66. void ulog_async_waiting_log(uint32_t time);
  67. #endif
  68. /*
  69. * dump the hex format data to log
  70. */
  71. void ulog_hexdump(const char *tag, size_t width, uint8_t *buf, size_t size);
  72. /*
  73. * Another log output API. This API is more difficult to use than LOG_X API.
  74. */
  75. void ulog_voutput(uint32_t level, const char *tag, int newline, const char *format, va_list args);
  76. void ulog_output(uint32_t level, const char *tag, int newline, const char *format, ...);
  77. void ulog_raw(const char *format, ...);
  78. void read_flash_log(uint8_t *logbuf, size_t index, size_t size);
  79. size_t read_recent_flash_log(void *buf, size_t size);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif /* _ULOG_H_ */