Man, Jianting (Meco) 8b58577230
[ulog][rtc][time][bug] solve the interference when enable the ulog timestamp (#5687)
* [ulog] 解决ulog开启时间戳后与libc time以及rtc驱动相关函数干涉的问题
* ulog:当发生递归输出时,后续递归想要输出的内容可能会因为防范递归的判断而无法输出
因此修改输出规则,在发生递归时,采用简单的,无格式的方式直接输出。这样既保证不会发生递归输出,也可以保证递归输出的部分可以正常输出。
* [ulog] size_t->rt_size_t NULL->RT_NULL
2022-03-21 14:06:17 +08:00

58 lines
1.3 KiB
C

/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-04 armink the first version
*/
#include <rthw.h>
#include <ulog.h>
#ifdef ULOG_BACKEND_USING_CONSOLE
#if defined(ULOG_ASYNC_OUTPUT_BY_THREAD) && ULOG_ASYNC_OUTPUT_THREAD_STACK < 384
#error "The thread stack size must more than 384 when using async output by thread (ULOG_ASYNC_OUTPUT_BY_THREAD)"
#endif
static struct ulog_backend console = { 0 };
void ulog_console_backend_output(struct ulog_backend *backend, rt_uint32_t level, const char *tag, rt_bool_t is_raw,
const char *log, rt_size_t len)
{
#ifdef RT_USING_DEVICE
rt_device_t dev = rt_console_get_device();
if (dev == RT_NULL)
{
rt_hw_console_output(log);
}
else
{
rt_uint16_t old_flag = dev->open_flag;
dev->open_flag |= RT_DEVICE_FLAG_STREAM;
rt_device_write(dev, 0, log, len);
dev->open_flag = old_flag;
}
#else
rt_hw_console_output(log);
#endif
}
int ulog_console_backend_init(void)
{
ulog_init();
console.output = ulog_console_backend_output;
ulog_backend_register(&console, "console", RT_TRUE);
return 0;
}
INIT_PREV_EXPORT(ulog_console_backend_init);
#endif /* ULOG_BACKEND_USING_CONSOLE */