console_be.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-09-04 armink the first version
  9. */
  10. #include <rthw.h>
  11. #include <ulog.h>
  12. #ifdef ULOG_BACKEND_USING_CONSOLE
  13. #if defined(ULOG_ASYNC_OUTPUT_BY_THREAD) && ULOG_ASYNC_OUTPUT_THREAD_STACK < 384
  14. #error "The thread stack size must more than 384 when using async output by thread (ULOG_ASYNC_OUTPUT_BY_THREAD)"
  15. #endif
  16. static struct ulog_backend console = { 0 };
  17. void ulog_console_backend_output(struct ulog_backend *backend, rt_uint32_t level, const char *tag, rt_bool_t is_raw,
  18. const char *log, rt_size_t len)
  19. {
  20. #ifdef RT_USING_DEVICE
  21. rt_device_t dev = rt_console_get_device();
  22. if (dev == RT_NULL)
  23. {
  24. rt_hw_console_output(log);
  25. }
  26. else
  27. {
  28. rt_device_write(dev, 0, log, len);
  29. }
  30. #else
  31. rt_hw_console_output(log);
  32. #endif
  33. }
  34. int ulog_console_backend_init(void)
  35. {
  36. ulog_init();
  37. console.output = ulog_console_backend_output;
  38. ulog_backend_register(&console, "console", RT_TRUE);
  39. return 0;
  40. }
  41. INIT_PREV_EXPORT(ulog_console_backend_init);
  42. #endif /* ULOG_BACKEND_USING_CONSOLE */