From 34b6731b82d9f050d1347a68be418d70c491e305 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 5 Aug 2023 17:15:40 +0930 Subject: [PATCH] lightningd: don't return to a default filter level if there are no per-file filters. In this case, the user's default was info, but they specifically asked for debug from one plugin. Since there were no per-file filters, it set filtering to the default level, info, and rejected it. Since it's been explicitly filtered in, we need to pass it at this point. Reported-by: @wtogami Fixes: #6503 Signed-off-by: Rusty Russell --- lightningd/log.c | 15 ++++++++++++--- tests/test_misc.py | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lightningd/log.c b/lightningd/log.c index 59bcb2aad..4c9b6b9be 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -206,6 +206,7 @@ static void log_to_files(const char *log_prefix, { char tstamp[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ ")]; char *entry, *nodestr; + bool filtered; if (print_timestamps) { char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ ")]; @@ -243,12 +244,15 @@ static void log_to_files(const char *log_prefix, /* In complex configurations, we tell loggers to overshare: then we * need to filter here to see if we really want it. */ + filtered = false; if (print_filters) { enum log_level filter; if (filter_level(print_filters, entry_prefix, nodestr, &filter)) { if (level < filter) return; + /* Even if they specify a default filter level of 'INFO', this overrides */ + filtered = true; } } @@ -264,10 +268,15 @@ static void log_to_files(const char *log_prefix, if (!filter_level(&log_files[i]->print_filters, entry_prefix, nodestr, &filter)) { /* If we haven't set default yet, only log UNUSUAL */ - if (default_print_level) - filter = *default_print_level; - else + if (!default_print_level) filter = LOG_UNUSUAL; + else { + /* If we've filtered it already, it passes */ + if (filtered) + filter = level; + else + filter = *default_print_level; + } } if (level < filter) continue; diff --git a/tests/test_misc.py b/tests/test_misc.py index a62833e71..ef410852a 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3076,7 +3076,6 @@ def test_log_filter(node_factory): assert all([' {}-'.format(l1.info['id']) in l for l in lines]) -@pytest.mark.xfail(strict=True) def test_log_filter_bug(node_factory): """Test the log-level option with overriding to a more verbose setting""" log_plugin = os.path.join(os.getcwd(), 'tests/plugins/log.py')