1
0

console_be.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-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;
  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, size_t len)
  19. {
  20. rt_device_t dev = rt_console_get_device();
  21. #ifdef RT_USING_DEVICE
  22. if (dev == RT_NULL)
  23. {
  24. rt_hw_console_output(log);
  25. }
  26. else
  27. {
  28. rt_uint16_t old_flag = dev->open_flag;
  29. dev->open_flag |= RT_DEVICE_FLAG_STREAM;
  30. rt_device_write(dev, 0, log, len);
  31. dev->open_flag = old_flag;
  32. }
  33. #else
  34. rt_hw_console_output(log);
  35. #endif
  36. }
  37. int ulog_console_backend_init(void)
  38. {
  39. console.output = ulog_console_backend_output;
  40. ulog_backend_register(&console, "console", RT_TRUE);
  41. return 0;
  42. }
  43. INIT_COMPONENT_EXPORT(ulog_console_backend_init);
  44. #endif /* ULOG_BACKEND_USING_CONSOLE */