提交 e588dfa6 编写于 作者: armink_ztl's avatar armink_ztl

[component][ulog] Add newline param for ulog_output API.

上级 12a803bc
......@@ -95,7 +95,7 @@ void vsyslog(int priority, const char *format, va_list args)
priority |= local_facility;
}
ulog_voutput(priority, local_ident, format, args);
ulog_voutput(priority, local_ident, RT_TRUE, format, args);
}
/**
......@@ -169,7 +169,7 @@ static const char *get_month_str(uint8_t month)
}
}
RT_WEAK rt_size_t syslog_formater(char *log_buf, int level, const char *tag, const char *format, va_list args)
RT_WEAK rt_size_t syslog_formater(char *log_buf, int level, const char *tag, rt_bool_t newline, const char *format, va_list args)
{
extern size_t ulog_strcpy(size_t cur_len, char *dst, const char *src);
......@@ -252,7 +252,10 @@ RT_WEAK rt_size_t syslog_formater(char *log_buf, int level, const char *tag, con
}
/* package newline sign */
log_len += ulog_strcpy(log_len, log_buf + log_len, ULOG_NEWLINE_SIGN);
if (newline)
{
log_len += ulog_strcpy(log_len, log_buf + log_len, ULOG_NEWLINE_SIGN);
}
return log_len;
}
......
......@@ -218,7 +218,8 @@ static char *get_log_buf(void)
}
}
RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *tag, const char *format, va_list args)
RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *tag, rt_bool_t newline,
const char *format, va_list args)
{
rt_size_t log_len = 0, newline_len = rt_strlen(ULOG_NEWLINE_SIGN);
int fmt_result;
......@@ -340,7 +341,10 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
}
/* package newline sign */
log_len += ulog_strcpy(log_len, log_buf + log_len, ULOG_NEWLINE_SIGN);
if (newline)
{
log_len += ulog_strcpy(log_len, log_buf + log_len, ULOG_NEWLINE_SIGN);
}
#ifdef ULOG_USING_COLOR
/* add CSI end sign */
......@@ -449,10 +453,11 @@ static void do_output(rt_uint32_t level, const char *tag, rt_bool_t is_raw, cons
*
* @param level level
* @param tag tag
* @param newline has_newline
* @param format output format
* @param args variable argument list
*/
void ulog_voutput(rt_uint32_t level, const char *tag, const char *format, va_list args)
void ulog_voutput(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, va_list args)
{
char *log_buf = NULL;
rt_size_t log_len = 0;
......@@ -499,10 +504,10 @@ void ulog_voutput(rt_uint32_t level, const char *tag, const char *format, va_lis
output_lock();
#ifndef ULOG_USING_SYSLOG
log_len = ulog_formater(log_buf, level, tag, format, args);
log_len = ulog_formater(log_buf, level, tag, newline, format, args);
#else
extern rt_size_t syslog_formater(char *log_buf, rt_uint8_t level, const char *tag, const char *format, va_list args);
log_len = syslog_formater(log_buf, level, tag, format, args);
extern rt_size_t syslog_formater(char *log_buf, rt_uint8_t level, const char *tag, rt_bool_t newline, const char *format, va_list args);
log_len = syslog_formater(log_buf, level, tag, newline, format, args);
#endif /* ULOG_USING_SYSLOG */
#ifdef ULOG_USING_FILTER
......@@ -532,17 +537,18 @@ void ulog_voutput(rt_uint32_t level, const char *tag, const char *format, va_lis
*
* @param level level
* @param tag tag
* @param newline has newline
* @param format output format
* @param ... args
*/
void ulog_output(rt_uint32_t level, const char *tag, const char *format, ...)
void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...)
{
va_list args;
/* args point to the first variable parameter */
va_start(args, format);
ulog_voutput(level, tag, format, args);
ulog_voutput(level, tag, newline, format, args);
va_end(args);
}
......
......@@ -84,8 +84,8 @@ void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t
/*
* Another log output API. This API is difficult to use than LOG_X API.
*/
void ulog_voutput(rt_uint32_t level, const char *tag, const char *format, va_list args);
void ulog_output(rt_uint32_t level, const char *tag, const char *format, ...);
void ulog_voutput(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, va_list args);
void ulog_output(rt_uint32_t level, const char *tag, rt_bool_t newline, const char *format, ...);
void ulog_raw(const char *format, ...);
#ifdef __cplusplus
......
......@@ -40,10 +40,16 @@ extern "C" {
#undef DBG_WARNING
#undef DBG_INFO
#undef DBG_LOG
#undef dbg_log
#define DBG_ERROR LOG_LVL_ERROR
#define DBG_WARNING LOG_LVL_WARNING
#define DBG_INFO LOG_LVL_INFO
#define DBG_LOG LOG_LVL_DBG
#define dbg_log(level, ...) \
if ((level) <= DBG_LEVEL) \
{ \
ulog_output(level, LOG_TAG, RT_FALSE, __VA_ARGS__);\
}
#if !defined(LOG_TAG)
/* compatible for rtdbg */
......@@ -64,25 +70,25 @@ extern "C" {
#endif /* !defined(LOG_LVL) */
#if (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG)
#define ulog_d(TAG, ...) ulog_output(LOG_LVL_DBG, TAG, __VA_ARGS__)
#define ulog_d(TAG, ...) ulog_output(LOG_LVL_DBG, TAG, RT_TRUE, __VA_ARGS__)
#else
#define ulog_d(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG) */
#if (LOG_LVL >= LOG_LVL_INFO) && (ULOG_OUTPUT_LVL >= LOG_LVL_INFO)
#define ulog_i(TAG, ...) ulog_output(LOG_LVL_INFO, TAG, __VA_ARGS__)
#define ulog_i(TAG, ...) ulog_output(LOG_LVL_INFO, TAG, RT_TRUE, __VA_ARGS__)
#else
#define ulog_i(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_INFO) && (ULOG_OUTPUT_LVL >= LOG_LVL_INFO) */
#if (LOG_LVL >= LOG_LVL_WARNING) && (ULOG_OUTPUT_LVL >= LOG_LVL_WARNING)
#define ulog_w(TAG, ...) ulog_output(LOG_LVL_WARNING, TAG, __VA_ARGS__)
#define ulog_w(TAG, ...) ulog_output(LOG_LVL_WARNING, TAG, RT_TRUE, __VA_ARGS__)
#else
#define ulog_w(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_WARNING) && (ULOG_OUTPUT_LVL >= LOG_LVL_WARNING) */
#if (LOG_LVL >= LOG_LVL_ERROR) && (ULOG_OUTPUT_LVL >= LOG_LVL_ERROR)
#define ulog_e(TAG, ...) ulog_output(LOG_LVL_ERROR, TAG, __VA_ARGS__)
#define ulog_e(TAG, ...) ulog_output(LOG_LVL_ERROR, TAG, RT_TRUE, __VA_ARGS__)
#else
#define ulog_e(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_ERROR) && (ULOG_OUTPUT_LVL >= LOG_LVL_ERROR) */
......@@ -92,7 +98,7 @@ extern "C" {
#define ULOG_ASSERT(EXPR) \
if (!(EXPR)) \
{ \
ulog_output(LOG_LVL_ASSERT, LOG_TAG, "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \
ulog_output(LOG_LVL_ASSERT, LOG_TAG, RT_TRUE, "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \
ulog_flush(); \
while (1); \
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册