ulog.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-08-25 armink the first version
  9. */
  10. #ifndef _ULOG_H_
  11. #define _ULOG_H_
  12. #include <rtthread.h>
  13. #include "ulog_def.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #define ULOG_VERSION_STR "0.1.1"
  18. /*
  19. * ulog init and deint
  20. */
  21. int ulog_init(void);
  22. int ulog_async_init(void);
  23. void ulog_output_lock_enabled(rt_bool_t enabled);
  24. void ulog_deinit(void);
  25. /*
  26. * output different level log by LOG_X API
  27. *
  28. * NOTE: The `LOG_TAG` and `LOG_LVL` must be defined before including the <ulog.h> when you want to use LOG_X API.
  29. *
  30. * #define LOG_TAG "example"
  31. * #define LOG_LVL LOG_LVL_DBG
  32. * #include <ulog.h>
  33. *
  34. * Then you can using LOG_X API to output log
  35. *
  36. * LOG_D("this is a debug log!");
  37. * LOG_E("this is a error log!");
  38. */
  39. #define LOG_E(...) ulog_e(LOG_TAG, __VA_ARGS__)
  40. #define LOG_W(...) ulog_w(LOG_TAG, __VA_ARGS__)
  41. #define LOG_I(...) ulog_i(LOG_TAG, __VA_ARGS__)
  42. #define LOG_D(...) ulog_d(LOG_TAG, __VA_ARGS__)
  43. #define LOG_RAW(...) ulog_raw(__VA_ARGS__)
  44. #define LOG_HEX(name, width, buf, size) ulog_hex(name, width, buf, size)
  45. /*
  46. * backend register and unregister
  47. */
  48. rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool_t support_color);
  49. rt_err_t ulog_backend_unregister(ulog_backend_t backend);
  50. #ifdef ULOG_USING_FILTER
  51. /*
  52. * log filter setting
  53. */
  54. int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level);
  55. rt_uint32_t ulog_tag_lvl_filter_get(const char *tag);
  56. rt_slist_t *ulog_tag_lvl_list_get(void);
  57. void ulog_global_filter_lvl_set(rt_uint32_t level);
  58. rt_uint32_t ulog_global_filter_lvl_get(void);
  59. void ulog_global_filter_tag_set(const char *tag);
  60. const char *ulog_global_filter_tag_get(void);
  61. void ulog_global_filter_kw_set(const char *keyword);
  62. const char *ulog_global_filter_kw_get(void);
  63. #endif /* ULOG_USING_FILTER */
  64. /*
  65. * flush all backends's log
  66. */
  67. void ulog_flush(void);
  68. #ifdef ULOG_USING_ASYNC_OUTPUT
  69. /*
  70. * asynchronous output API
  71. */
  72. void ulog_async_output(void);
  73. void ulog_async_output_enabled(rt_bool_t enabled);
  74. void ulog_async_waiting_log(rt_int32_t time);
  75. #endif
  76. /*
  77. * dump the hex format data to log
  78. */
  79. void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t size);
  80. /*
  81. * Another log output API. This API is more difficult to use than LOG_X API.
  82. */
  83. void ulog_voutput(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, va_list args);
  84. void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...);
  85. void ulog_raw(const char *format, ...);
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. #endif /* _ULOG_H_ */