From c990f0a026d5143c0e73cf8d21a30d60a4a81308 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 8 Nov 2018 11:23:03 +0800 Subject: [PATCH] [component][ulog] Add tag filter to hexdump function. --- components/utilities/ulog/ulog.c | 15 ++++++++++----- components/utilities/ulog/ulog.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c index 54c4c7c26..e7dd665f4 100644 --- a/components/utilities/ulog/ulog.c +++ b/components/utilities/ulog/ulog.c @@ -625,17 +625,17 @@ void ulog_raw(const char *format, ...) /** * dump the hex format data to log * - * @param name name for hex object, it will show on log header + * @param tag name for hex object, it will show on log header * @param width hex number for every line, such as: 16, 32 * @param buf hex buffer * @param size buffer size */ -void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t size) +void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t size) { #define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ') rt_size_t i, j; - rt_size_t log_len = 0, name_len = rt_strlen(name); + rt_size_t log_len = 0, name_len = rt_strlen(tag); char *log_buf = NULL, dump_string[8]; int fmt_result; @@ -644,7 +644,7 @@ void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t #ifdef ULOG_USING_FILTER /* level filter */ #ifndef ULOG_USING_SYSLOG - if (LOG_LVL_DBG > ulog.filter.level) + if (LOG_LVL_DBG > ulog.filter.level || LOG_LVL_DBG > ulog_tag_lvl_filter_get(tag)) { return; } @@ -654,6 +654,11 @@ void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t return; } #endif /* ULOG_USING_SYSLOG */ + else if (!rt_strstr(tag, ulog.filter.tag)) + { + /* tag filter */ + return; + } #endif /* ULOG_USING_FILTER */ /* get log buffer */ @@ -668,7 +673,7 @@ void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t if (i == 0) { log_len += ulog_strcpy(log_len, log_buf + log_len, "D/HEX "); - log_len += ulog_strcpy(log_len, log_buf + log_len, name); + log_len += ulog_strcpy(log_len, log_buf + log_len, tag); log_len += ulog_strcpy(log_len, log_buf + log_len, ": "); } else diff --git a/components/utilities/ulog/ulog.h b/components/utilities/ulog/ulog.h index ad0525c9a..ab203602b 100644 --- a/components/utilities/ulog/ulog.h +++ b/components/utilities/ulog/ulog.h @@ -83,7 +83,7 @@ void ulog_async_waiting_log(rt_int32_t time); /* * dump the hex format data to log */ -void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t size); +void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t size); /* * Another log output API. This API is more difficult to use than LOG_X API. -- GitLab