console_be.c 1.2 KB
Newer Older
1
/*
2
 * Copyright (c) 2006-2022, RT-Thread Development Team
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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

armink_ztl's avatar
armink_ztl 已提交
20
static struct ulog_backend console = { 0 };
21 22

void ulog_console_backend_output(struct ulog_backend *backend, rt_uint32_t level, const char *tag, rt_bool_t is_raw,
23
        const char *log, rt_size_t len)
24
{
25
#ifdef RT_USING_DEVICE
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    rt_device_t dev = rt_console_get_device();

    if (dev == RT_NULL)
    {
        rt_hw_console_output(log);
    }
    else
    {
        rt_device_write(dev, 0, log, len);
    }
#else
    rt_hw_console_output(log);
#endif

}

int ulog_console_backend_init(void)
{
44
    ulog_init();
45 46 47 48 49 50
    console.output = ulog_console_backend_output;

    ulog_backend_register(&console, "console", RT_TRUE);

    return 0;
}
51
INIT_PREV_EXPORT(ulog_console_backend_init);
52 53

#endif /* ULOG_BACKEND_USING_CONSOLE */