Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log.c | 29 +++++++++++++++++++++--------
tests/check_log.c | 21 +++++++++++++++++++++
2 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/lib/log.c b/lib/log.c
index 2997eac..998ad6e 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -82,14 +82,27 @@ _cs_matches_filter_(struct qb_log_callsite *cs,
if (strcmp(text, "*") == 0) {
return QB_TRUE;
}
- if (type == QB_LOG_FILTER_FILE) {
- if (strstr(cs->filename, text)) {
- match = QB_TRUE;
- }
- } else if (type == QB_LOG_FILTER_FUNCTION) {
- if (strstr(cs->function, text)) {
- match = QB_TRUE;
- }
+ if (type == QB_LOG_FILTER_FILE ||
+ type == QB_LOG_FILTER_FUNCTION) {
+ char token[500];
+ const char *offset = NULL;
+ const char *next = text;
+
+ do {
+ offset = next;
+ next = strchrnul(offset, ',');
+ snprintf(token, 499, "%.*s", (int)(next - offset), offset);
+
+ if (type == QB_LOG_FILTER_FILE) {
+ match = (strstr(cs->filename, token) != NULL);
+ } else {
+ match = (strstr(cs->function, token) != NULL);
+ }
+ if (!match && next[0] != 0) {
+ next++;
+ }
+
+ } while (match == QB_FALSE && next != NULL && next[0] != 0);
} else if (type == QB_LOG_FILTER_FORMAT) {
if (strstr(cs->format, text)) {
match = QB_TRUE;
diff --git a/tests/check_log.c b/tests/check_log.c
index c17b787..153f254 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -158,6 +158,16 @@ _test_logger(int32_t t,
num_msgs++;
}
+static void log_also(void)
+{
+ qb_log(LOG_INFO, "yes please");
+}
+
+static void log_and_this_too(void)
+{
+ qb_log(LOG_INFO, "this too please");
+}
+
static void log_it_please(void)
{
qb_enter();
@@ -228,6 +238,17 @@ START_TEST(test_log_basic)
ck_assert_int_eq(num_msgs, 0);
qb_log(LOG_DEBUG, "try if you: log_it_please()");
ck_assert_int_eq(num_msgs, 1);
+
+ qb_log_filter_ctl(t, QB_LOG_FILTER_CLEAR_ALL,
+ QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
+ qb_log_filter_ctl(t, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FUNCTION,
+ "log_also,log_and_this_too",
+ LOG_DEBUG);
+ num_msgs = 0;
+ log_also();
+ log_and_this_too();
+ ck_assert_int_eq(num_msgs, 2);
}
END_TEST
--
1.7.6
Show replies by date