ulog.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2018, 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.0"
  18. /*
  19. * ulog init and deint
  20. */
  21. int ulog_init(void);
  22. void ulog_deinit(void);
  23. /*
  24. * output different level log by LOG_X API
  25. *
  26. * NOTE: The `LOG_TAG` and `LOG_LVL` must be defined before including the <ulog.h> when you want to use LOG_X API.
  27. *
  28. * #define LOG_TAG "example"
  29. * #define LOG_LVL LOG_LVL_DBG
  30. * #include <ulog.h>
  31. *
  32. * Then you can using LOG_X API to output log
  33. *
  34. * LOG_D("this is a debug log!");
  35. * LOG_E("this is a error log!");
  36. */
  37. #define LOG_E(...) ulog_e(LOG_TAG, __VA_ARGS__)
  38. #define LOG_W(...) ulog_w(LOG_TAG, __VA_ARGS__)
  39. #define LOG_I(...) ulog_i(LOG_TAG, __VA_ARGS__)
  40. #define LOG_D(...) ulog_d(LOG_TAG, __VA_ARGS__)
  41. #define LOG_RAW(...) ulog_raw(__VA_ARGS__)
  42. /*
  43. * backend register and unregister
  44. */
  45. rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool_t support_color);
  46. rt_err_t ulog_backend_unregister(ulog_backend_t backend);
  47. #ifdef ULOG_USING_FILTER
  48. /*
  49. * log filter setting
  50. */
  51. int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level);
  52. rt_uint32_t ulog_tag_lvl_filter_get(const char *tag);
  53. void ulog_global_filter_lvl_set(rt_uint32_t level);
  54. void ulog_global_filter_tag_set(const char *tag);
  55. void ulog_global_filter_kw_set(const char *keyword);
  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(rt_int32_t time);
  67. #endif
  68. /*
  69. * dump the hex format data to log
  70. */
  71. void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_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(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, va_list args);
  76. void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...);
  77. void ulog_raw(const char *format, ...);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* _ULOG_H_ */