@@ -274,6 +274,7 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
274274 /* add time info */
275275 {
276276#ifdef ULOG_TIME_USING_TIMESTAMP
277+ extern struct tm * localtime_r (const time_t * t , struct tm * r );
277278 static struct timeval now ;
278279 static struct tm * tm , tm_tmp ;
279280 static rt_bool_t check_usec_support = RT_FALSE , usec_is_support = RT_FALSE ;
@@ -439,6 +440,11 @@ void ulog_output_to_all_backend(rt_uint32_t level, const char *tag, rt_bool_t is
439440#if !defined(ULOG_USING_COLOR ) || defined(ULOG_USING_SYSLOG )
440441 backend -> output (backend , level , tag , is_raw , log , size );
441442#else
443+ if (backend -> filter && backend -> filter (backend , level , tag , is_raw , log , size ) == RT_FALSE )
444+ {
445+ /* backend's filter is not match, so skip output */
446+ continue ;
447+ }
442448 if (backend -> support_color || is_raw )
443449 {
444450 backend -> output (backend , level , tag , is_raw , log , size );
@@ -447,7 +453,7 @@ void ulog_output_to_all_backend(rt_uint32_t level, const char *tag, rt_bool_t is
447453 {
448454 /* recalculate the log start address and log size when backend not supported color */
449455 rt_size_t color_info_len = 0 , output_size = size ;
450- char * output_log = log ;
456+ const char * output_log = log ;
451457
452458 if (color_output_info [level ] != RT_NULL )
453459 color_info_len = rt_strlen (color_output_info [level ]);
@@ -1300,6 +1306,41 @@ rt_err_t ulog_backend_unregister(ulog_backend_t backend)
13001306 return RT_EOK ;
13011307}
13021308
1309+ rt_err_t ulog_backend_set_filter (ulog_backend_t backend , ulog_backend_filter_t filter )
1310+ {
1311+ rt_base_t level ;
1312+ RT_ASSERT (backend );
1313+
1314+ level = rt_hw_interrupt_disable ();
1315+ backend -> filter = filter ;
1316+ rt_hw_interrupt_enable (level );
1317+
1318+ return RT_EOK ;
1319+ }
1320+
1321+ ulog_backend_t ulog_backend_find (const char * name )
1322+ {
1323+ rt_base_t level ;
1324+ rt_slist_t * node ;
1325+ ulog_backend_t backend ;
1326+
1327+ RT_ASSERT (ulog .init_ok );
1328+
1329+ level = rt_hw_interrupt_disable ();
1330+ for (node = rt_slist_first (& ulog .backend_list ); node ; node = rt_slist_next (node ))
1331+ {
1332+ backend = rt_slist_entry (node , struct ulog_backend , list );
1333+ if (rt_strncmp (backend -> name , name , RT_NAME_MAX ) == 0 )
1334+ {
1335+ rt_hw_interrupt_enable (level );
1336+ return backend ;
1337+ }
1338+ }
1339+
1340+ rt_hw_interrupt_enable (level );
1341+ return RT_NULL ;
1342+ }
1343+
13031344#ifdef ULOG_USING_ASYNC_OUTPUT
13041345/**
13051346 * asynchronous output logs to all backends
0 commit comments