[ulog] support ulog_async_output_enabled
This commit is contained in:
parent
7b4e52bd79
commit
befb15b428
|
@ -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
|
#ifdef ULOG_USING_ASYNC_OUTPUT
|
||||||
rt_size_t log_buf_size = log_len + sizeof((char)'\0');
|
rt_size_t log_buf_size = log_len + sizeof((char)'\0');
|
||||||
|
if (ulog.async_enabled)
|
||||||
if (is_raw == RT_FALSE)
|
|
||||||
{
|
{
|
||||||
rt_rbb_blk_t log_blk;
|
if (is_raw == RT_FALSE)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
/* package the log frame */
|
rt_rbb_blk_t log_blk;
|
||||||
log_frame = (ulog_frame_t) log_blk->buf;
|
ulog_frame_t log_frame;
|
||||||
log_frame->magic = ULOG_FRAME_MAGIC;
|
|
||||||
log_frame->is_raw = is_raw;
|
/* allocate log frame */
|
||||||
log_frame->level = level;
|
log_blk = rt_rbb_blk_alloc(ulog.async_rbb, RT_ALIGN(sizeof(struct ulog_frame) + log_buf_size, RT_ALIGN_SIZE));
|
||||||
log_frame->log_len = log_len;
|
if (log_blk)
|
||||||
log_frame->tag = tag;
|
{
|
||||||
log_frame->log = (const char *)log_blk->buf + sizeof(struct ulog_frame);
|
/* package the log frame */
|
||||||
/* copy log data */
|
log_frame = (ulog_frame_t) log_blk->buf;
|
||||||
rt_strncpy((char *)(log_blk->buf + sizeof(struct ulog_frame)), log_buf, log_buf_size);
|
log_frame->magic = ULOG_FRAME_MAGIC;
|
||||||
/* put the block */
|
log_frame->is_raw = is_raw;
|
||||||
rt_rbb_blk_put(log_blk);
|
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)
|
||||||
|
{
|
||||||
|
rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, (rt_uint16_t)log_buf_size);
|
||||||
/* send a notice */
|
/* send a notice */
|
||||||
rt_sem_release(&ulog.async_notice);
|
rt_sem_release(&ulog.async_notice);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return;
|
||||||
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)
|
#endif /* ULOG_USING_ASYNC_OUTPUT */
|
||||||
{
|
|
||||||
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
|
|
||||||
/* is in thread context */
|
/* is in thread context */
|
||||||
if (rt_interrupt_get_nest() == 0)
|
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);
|
ulog_console_backend_output(RT_NULL, level, tag, is_raw, log_buf, log_len);
|
||||||
#endif /* ULOG_BACKEND_USING_CONSOLE */
|
#endif /* ULOG_BACKEND_USING_CONSOLE */
|
||||||
}
|
}
|
||||||
#endif /* ULOG_USING_ASYNC_OUTPUT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue