summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorguozhanxin <[email protected]>2023-07-04 13:56:05 +0800
committerguo <[email protected]>2023-07-05 04:34:25 +0800
commitbefb15b42895ac9067441fde814a05270107607f (patch)
treee4a59d621383182673007c2de387142378a6fe97 /components
parent7b4e52bd797ca8956f7ac08e0b3d31a8286da8f4 (diff)
[ulog] support ulog_async_output_enabled
Diffstat (limited to 'components')
-rw-r--r--components/utilities/ulog/ulog.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c
index c83d40dbfe..359677d333 100644
--- a/components/utilities/ulog/ulog.c
+++ b/components/utilities/ulog/ulog.c
@@ -559,49 +559,53 @@ static void do_output(rt_uint32_t level, const char *tag, rt_bool_t is_raw, cons
{
#ifdef ULOG_USING_ASYNC_OUTPUT
rt_size_t log_buf_size = log_len + sizeof((char)'\0');
-
- if (is_raw == RT_FALSE)
+ if (ulog.async_enabled)
{
- rt_rbb_blk_t log_blk;
- ulog_frame_t log_frame;
+ if (is_raw == RT_FALSE)
+ {
+ rt_rbb_blk_t log_blk;
+ ulog_frame_t log_frame;
- /* allocate log frame */
- log_blk = rt_rbb_blk_alloc(ulog.async_rbb, RT_ALIGN(sizeof(struct ulog_frame) + log_buf_size, RT_ALIGN_SIZE));
- if (log_blk)
+ /* allocate log frame */
+ log_blk = rt_rbb_blk_alloc(ulog.async_rbb, RT_ALIGN(sizeof(struct ulog_frame) + log_buf_size, RT_ALIGN_SIZE));
+ if (log_blk)
+ {
+ /* package the log frame */
+ log_frame = (ulog_frame_t) log_blk->buf;
+ log_frame->magic = ULOG_FRAME_MAGIC;
+ log_frame->is_raw = is_raw;
+ log_frame->level = level;
+ log_frame->log_len = log_len;
+ log_frame->tag = tag;
+ log_frame->log = (const char *)log_blk->buf + sizeof(struct ulog_frame);
+ /* copy log data */
+ rt_strncpy((char *)(log_blk->buf + sizeof(struct ulog_frame)), log_buf, log_buf_size);
+ /* put the block */
+ rt_rbb_blk_put(log_blk);
+ /* send a notice */
+ rt_sem_release(&ulog.async_notice);
+ }
+ else
+ {
+ static rt_bool_t already_output = RT_FALSE;
+ if (already_output == RT_FALSE)
+ {
+ rt_kprintf("Warning: There is no enough buffer for saving async log,"
+ " please increase the ULOG_ASYNC_OUTPUT_BUF_SIZE option.\n");
+ already_output = RT_TRUE;
+ }
+ }
+ }
+ else if (ulog.async_rb)
{
- /* package the log frame */
- log_frame = (ulog_frame_t) log_blk->buf;
- log_frame->magic = ULOG_FRAME_MAGIC;
- log_frame->is_raw = is_raw;
- log_frame->level = level;
- log_frame->log_len = log_len;
- log_frame->tag = tag;
- log_frame->log = (const char *)log_blk->buf + sizeof(struct ulog_frame);
- /* copy log data */
- rt_strncpy((char *)(log_blk->buf + sizeof(struct ulog_frame)), log_buf, log_buf_size);
- /* put the block */
- rt_rbb_blk_put(log_blk);
+ rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, (rt_uint16_t)log_buf_size);
/* send a notice */
rt_sem_release(&ulog.async_notice);
}
- else
- {
- static rt_bool_t already_output = RT_FALSE;
- if (already_output == RT_FALSE)
- {
- rt_kprintf("Warning: There is no enough buffer for saving async log,"
- " please increase the ULOG_ASYNC_OUTPUT_BUF_SIZE option.\n");
- already_output = RT_TRUE;
- }
- }
- }
- else if (ulog.async_rb)
- {
- rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, (rt_uint16_t)log_buf_size);
- /* send a notice */
- rt_sem_release(&ulog.async_notice);
+
+ return;
}
-#else
+#endif /* ULOG_USING_ASYNC_OUTPUT */
/* is in thread context */
if (rt_interrupt_get_nest() == 0)
{
@@ -618,7 +622,6 @@ static void do_output(rt_uint32_t level, const char *tag, rt_bool_t is_raw, cons
ulog_console_backend_output(RT_NULL, level, tag, is_raw, log_buf, log_len);
#endif /* ULOG_BACKEND_USING_CONSOLE */
}
-#endif /* ULOG_USING_ASYNC_OUTPUT */
}
/**