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

[component][ulog] Add filter get API.

上级 2fe79faf
...@@ -74,15 +74,6 @@ ...@@ -74,15 +74,6 @@
#error "the log line buffer size must more than 80" #error "the log line buffer size must more than 80"
#endif #endif
/* tag's level filter */
struct tag_lvl_filter
{
char tag[ULOG_FILTER_TAG_MAX_LEN + 1];
rt_uint32_t level;
rt_slist_t list;
};
typedef struct tag_lvl_filter *tag_lvl_filter_t;
struct rt_ulog struct rt_ulog
{ {
rt_bool_t init_ok; rt_bool_t init_ok;
...@@ -760,7 +751,7 @@ void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t ...@@ -760,7 +751,7 @@ void ulog_hexdump(const char *name, rt_size_t width, rt_uint8_t *buf, rt_size_t
int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level) int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level)
{ {
rt_slist_t *node; rt_slist_t *node;
tag_lvl_filter_t tag_lvl = NULL; ulog_tag_lvl_filter_t tag_lvl = NULL;
int result = RT_EOK; int result = RT_EOK;
RT_ASSERT(level <= LOG_FILTER_LVL_ALL); RT_ASSERT(level <= LOG_FILTER_LVL_ALL);
...@@ -773,7 +764,7 @@ int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level) ...@@ -773,7 +764,7 @@ int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level)
/* find the tag in list */ /* find the tag in list */
for (node = rt_slist_first(&ulog.filter.tag_lvl_list); node; node = rt_slist_next(node)) for (node = rt_slist_first(&ulog.filter.tag_lvl_list); node; node = rt_slist_next(node))
{ {
tag_lvl = rt_slist_entry(node, struct tag_lvl_filter, list); tag_lvl = rt_slist_entry(node, struct ulog_tag_lvl_filter, list);
if (!rt_strncmp(tag_lvl->tag, tag, ULOG_FILTER_TAG_MAX_LEN)) if (!rt_strncmp(tag_lvl->tag, tag, ULOG_FILTER_TAG_MAX_LEN))
{ {
break; break;
...@@ -804,7 +795,7 @@ int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level) ...@@ -804,7 +795,7 @@ int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level)
if (level != LOG_FILTER_LVL_ALL) if (level != LOG_FILTER_LVL_ALL)
{ {
/* new a tag's level filter */ /* new a tag's level filter */
tag_lvl = (tag_lvl_filter_t)rt_malloc(sizeof(struct tag_lvl_filter)); tag_lvl = (ulog_tag_lvl_filter_t)rt_malloc(sizeof(struct ulog_tag_lvl_filter));
if (tag_lvl) if (tag_lvl)
{ {
rt_memset(tag_lvl->tag, 0 , sizeof(tag_lvl->tag)); rt_memset(tag_lvl->tag, 0 , sizeof(tag_lvl->tag));
...@@ -835,7 +826,7 @@ int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level) ...@@ -835,7 +826,7 @@ int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level)
rt_uint32_t ulog_tag_lvl_filter_get(const char *tag) rt_uint32_t ulog_tag_lvl_filter_get(const char *tag)
{ {
rt_slist_t *node; rt_slist_t *node;
tag_lvl_filter_t tag_lvl = NULL; ulog_tag_lvl_filter_t tag_lvl = NULL;
rt_uint32_t level = LOG_FILTER_LVL_ALL; rt_uint32_t level = LOG_FILTER_LVL_ALL;
if (!ulog.init_ok) if (!ulog.init_ok)
...@@ -846,7 +837,7 @@ rt_uint32_t ulog_tag_lvl_filter_get(const char *tag) ...@@ -846,7 +837,7 @@ rt_uint32_t ulog_tag_lvl_filter_get(const char *tag)
/* find the tag in list */ /* find the tag in list */
for (node = rt_slist_first(&ulog.filter.tag_lvl_list); node; node = rt_slist_next(node)) for (node = rt_slist_first(&ulog.filter.tag_lvl_list); node; node = rt_slist_next(node))
{ {
tag_lvl = rt_slist_entry(node, struct tag_lvl_filter, list); tag_lvl = rt_slist_entry(node, struct ulog_tag_lvl_filter, list);
if (!rt_strncmp(tag_lvl->tag, tag, ULOG_FILTER_TAG_MAX_LEN)) if (!rt_strncmp(tag_lvl->tag, tag, ULOG_FILTER_TAG_MAX_LEN))
{ {
level = tag_lvl->level; level = tag_lvl->level;
...@@ -859,6 +850,16 @@ rt_uint32_t ulog_tag_lvl_filter_get(const char *tag) ...@@ -859,6 +850,16 @@ rt_uint32_t ulog_tag_lvl_filter_get(const char *tag)
return level; return level;
} }
/**
* get the tag's level list on filter
*
* @return tag's level list
*/
rt_slist_t *ulog_tag_lvl_list_get(void)
{
return &ulog.filter.tag_lvl_list;
}
/** /**
* set log global filter level * set log global filter level
* *
...@@ -873,6 +874,18 @@ void ulog_global_filter_lvl_set(rt_uint32_t level) ...@@ -873,6 +874,18 @@ void ulog_global_filter_lvl_set(rt_uint32_t level)
ulog.filter.level = level; ulog.filter.level = level;
} }
/**
* get log global filter level
*
* @return log level: LOG_LVL_ASSERT, LOG_LVL_ERROR, LOG_LVL_WARNING, LOG_LVL_INFO, LOG_LVL_DBG
* LOG_FILTER_LVL_SILENT: disable all log output, except assert level
* LOG_FILTER_LVL_ALL: enable all log output
*/
rt_uint32_t ulog_global_filter_lvl_get(void)
{
return ulog.filter.level;
}
/** /**
* set log global filter tag * set log global filter tag
* *
...@@ -885,6 +898,16 @@ void ulog_global_filter_tag_set(const char *tag) ...@@ -885,6 +898,16 @@ void ulog_global_filter_tag_set(const char *tag)
rt_strncpy(ulog.filter.tag, tag, ULOG_FILTER_TAG_MAX_LEN); rt_strncpy(ulog.filter.tag, tag, ULOG_FILTER_TAG_MAX_LEN);
} }
/**
* get log global filter tag
*
* @return tag
*/
const char *ulog_global_filter_tag_get(void)
{
return ulog.filter.tag;
}
/** /**
* set log global filter keyword * set log global filter keyword
* *
...@@ -897,6 +920,16 @@ void ulog_global_filter_kw_set(const char *keyword) ...@@ -897,6 +920,16 @@ void ulog_global_filter_kw_set(const char *keyword)
rt_strncpy(ulog.filter.keyword, keyword, ULOG_FILTER_KW_MAX_LEN); rt_strncpy(ulog.filter.keyword, keyword, ULOG_FILTER_KW_MAX_LEN);
} }
/**
* get log global filter keyword
*
* @return keyword
*/
const char *ulog_global_filter_kw_get(void)
{
return ulog.filter.keyword;
}
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
#include <finsh.h> #include <finsh.h>
...@@ -1198,10 +1231,10 @@ void ulog_deinit(void) ...@@ -1198,10 +1231,10 @@ void ulog_deinit(void)
#ifdef ULOG_USING_FILTER #ifdef ULOG_USING_FILTER
/* deinit tag's level filter */ /* deinit tag's level filter */
{ {
tag_lvl_filter_t tag_lvl; ulog_tag_lvl_filter_t tag_lvl;
for (node = rt_slist_first(&ulog.filter.tag_lvl_list); node; node = rt_slist_next(node)) for (node = rt_slist_first(&ulog.filter.tag_lvl_list); node; node = rt_slist_next(node))
{ {
tag_lvl = rt_slist_entry(node, struct tag_lvl_filter, list); tag_lvl = rt_slist_entry(node, struct ulog_tag_lvl_filter, list);
rt_free(tag_lvl); rt_free(tag_lvl);
} }
} }
......
...@@ -58,9 +58,13 @@ rt_err_t ulog_backend_unregister(ulog_backend_t backend); ...@@ -58,9 +58,13 @@ rt_err_t ulog_backend_unregister(ulog_backend_t backend);
*/ */
int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level); int ulog_tag_lvl_filter_set(const char *tag, rt_uint32_t level);
rt_uint32_t ulog_tag_lvl_filter_get(const char *tag); rt_uint32_t ulog_tag_lvl_filter_get(const char *tag);
rt_slist_t *ulog_tag_lvl_list_get(void);
void ulog_global_filter_lvl_set(rt_uint32_t level); void ulog_global_filter_lvl_set(rt_uint32_t level);
rt_uint32_t ulog_global_filter_lvl_get(void);
void ulog_global_filter_tag_set(const char *tag); void ulog_global_filter_tag_set(const char *tag);
const char *ulog_global_filter_tag_get(void);
void ulog_global_filter_kw_set(const char *keyword); void ulog_global_filter_kw_set(const char *keyword);
const char *ulog_global_filter_kw_get(void);
#endif /* ULOG_USING_FILTER */ #endif /* ULOG_USING_FILTER */
/* /*
......
...@@ -165,6 +165,15 @@ extern "C" { ...@@ -165,6 +165,15 @@ extern "C" {
#define ULOG_FRAME_MAGIC 0x10 #define ULOG_FRAME_MAGIC 0x10
/* tag's level filter */
struct ulog_tag_lvl_filter
{
char tag[ULOG_FILTER_TAG_MAX_LEN + 1];
rt_uint32_t level;
rt_slist_t list;
};
typedef struct ulog_tag_lvl_filter *ulog_tag_lvl_filter_t;
struct ulog_frame struct ulog_frame
{ {
/* magic word is 0x10 ('lo') */ /* magic word is 0x10 ('lo') */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册