Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Severity-based logging, step 2 #25614

Merged
merged 12 commits into from
Sep 1, 2022
Merged

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Jul 14, 2022

This is an updated version of #25287 and the next steps in parent PR #25203 implementing, with Klement Tan, user-configurable, per-category severity log levels based on an idea by John Newbery and refined in GitHub discussions by Wladimir Van der Laan and Marco Falke.

  • simplify the BCLog::Level enum class and the LogLevelToStr() function and add documentation
  • update the logging logic to filter logs by log level both globally and per-category
  • add a hidden -loglevel help-debug config option to allow testing setting the global or per-category severity level on startup for logging categories enabled with the -debug configuration option or the logging RPC (Klement Tan)
  • add a trace log severity level selectable by the user; the plan is for the current debug messages to become trace, LogPrint ones to become debug, and LogPrintf ones to become info, warning, or error
$ ./src/bitcoind -help-debug | grep -A10 loglevel
  -loglevel=<level>|<category>:<level>
       Set the global or per-category severity level for logging categories
       enabled with the -debug configuration option or the logging RPC:
       info, debug, trace (default=info); warning and error levels are
       always logged. If <category>:<level> is supplied, the setting
       will override the global one and may be specified multiple times
       to set multiple category-specific levels. <category> can be:
       addrman, bench, blockstorage, cmpctblock, coindb, estimatefee,
       http, i2p, ipc, leveldb, libevent, lock, mempool, mempoolrej,
       net, proxy, prune, qt, rand, reindex, rpc, selectcoins, tor,
       util, validation, walletdb, zmq.

See the individual commit messages for details.

@DrahtBot
Copy link
Contributor

🕵️ @harding has been requested to review this pull request as specified in the REVIEWERS file.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 14, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24950 (Add config option to set max debug log size by tehelsper)
  • #16673 (Relog configuration args on debug.log rotation by LarryRuane)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@klementtan klementtan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK and crACK 5326f46 (except for some minor comments)

src/logging.cpp Outdated Show resolved Hide resolved
src/logging.cpp Outdated Show resolved Hide resolved
src/logging.cpp Show resolved Hide resolved
src/init/common.cpp Outdated Show resolved Hide resolved
@jonatack jonatack force-pushed the loglevel-config-option branch from 5326f46 to 9405e02 Compare July 20, 2022 11:25
@jonatack
Copy link
Member Author

jonatack commented Jul 20, 2022

Updated with review feedack by @klementtan (thanks!) per git range-diff 0897b18 5326f46 706805d

@klementtan
Copy link
Contributor

Code review ACK and tested ACK 706805d

Testing:

# Absence of debug log when loglevel=INFO
$  ./src/bitcoind -signet -loglevel=info
$  grep -o "net:debug" ~/.bitcoin/signet/debug.log | wc -l
      0

# Debug log present when loglevel=DEBUG
$ ./src/bitcoind -signet -loglevel=debug
$  grep -o "net:debug" ~/.bitcoin/signet/debug.log | wc -l
       2

# Category-specific log level. loglevel=net:info
$ ./src/bitcoind -signet -loglevel=net:info
Bitcoin Core starting
$  grep -o "net:debug" ~/.bitcoin/signet/debug.log | wc -l
       0

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review and Tested ACK 706805d

These are 4 first commits from #25203.
I understand they are the basis for the other changes in the log.

src/init/common.cpp Outdated Show resolved Hide resolved
doc/release-notes.md Outdated Show resolved Hide resolved
Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good but I think this is missing some documentation on how -loglevel and -debug relate to each other. Otherwise I think some users may be confused.

src/logging.h Show resolved Hide resolved
@jonatack jonatack force-pushed the loglevel-config-option branch 2 times, most recently from d50fd76 to 3b777e3 Compare August 11, 2022 14:43
@jonatack
Copy link
Member Author

jonatack commented Aug 11, 2022

Updated to address @fjahr's #25614 (review) suggestion in the -loglevel help with "Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC"), @w0xlt's release note feedback, @klementtan's suggestion in #25614 (comment) (which required updating the unit tests a bit) and a couple other minor improvements. Mind re-revewing, please? (Thanks!)

git diff 706805d 63215dd

diff --git a/doc/release-notes.md b/doc/release-notes.md
index 4680731280..9585144ce5 100644
--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -94,7 +94,7 @@ Tools and Utilities
 -------------------
 
 - A new `-loglevel` configuration option allows setting global and per-category
-  log severity levels. (#25203)
+  log severity levels. (#25614)
 
 Wallet
 ------
diff --git a/src/init/common.cpp b/src/init/common.cpp
index a0f5cb2a6e..a22d921b21 100644
--- a/src/init/common.cpp
+++ b/src/init/common.cpp
@@ -29,7 +29,7 @@ void AddLoggingArgs(ArgsManager& argsman)
         ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
     argsman.AddArg("-debugexclude=<category>", "Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except the specified category. This option can be specified multiple times to exclude multiple categories.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
     argsman.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
-    argsman.AddArg("-loglevel=<level>|<category>:<level>", strprintf("Set the global or per-category debug logging severity level: %s (default=%s). Error and warning levels are logged unconditionally.  If <category>:<level> is supplied, the setting will override the global one and may be specified multiple times to set multiple category-specific levels. <category> can be: %s.", LogInstance().LogLevelsString(), LogInstance().LogLevelToStr(), LogInstance().LogCategoriesString()), ArgsManager::DISALLOW_NEGATION | ArgsManager::DISALLOW_ELISION, OptionsCategory::DEBUG_TEST);
+    argsman.AddArg("-loglevel=<level>|<category>:<level>", strprintf("Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC: %s (default=%s); warning and error levels are always logged. If <category>:<level> is supplied, the setting will override the global one and may be specified multiple times to set multiple category-specific levels. <category> can be: %s.", LogInstance().LogLevelsString(), LogInstance().LogLevelToStr(BCLog::DEFAULT_LOG_LEVEL), LogInstance().LogCategoriesString()), ArgsManager::DISALLOW_NEGATION | ArgsManager::DISALLOW_ELISION, OptionsCategory::DEBUG_TEST);
     argsman.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
 #ifdef HAVE_THREAD_LOCAL
     argsman.AddArg("-logthreadnames", strprintf("Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u)", DEFAULT_LOGTHREADNAMES), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
@@ -64,13 +64,13 @@ void SetLoggingLevel(const ArgsManager& args)
             if (level_str.find_first_of(':', 3) == std::string::npos) {
                 // user passed a global log level, i.e. -loglevel=<level>
                 if (!LogInstance().SetLogLevel(level_str)) {
-                    InitWarning(strprintf(_("Unsupported global logging level -loglevel=%s. Valid values: %s"), level_str, LogInstance().LogLevelsString()));
+                    InitWarning(strprintf(_("Unsupported global logging level -loglevel=%s. Valid values: %s."), level_str, LogInstance().LogLevelsString()));
                 }
             } else {
                 // user passed a category-specific log level, i.e. -loglevel=<category>:<level>
                 const auto& toks = SplitString(level_str, ':');
                 if (!(toks.size() == 2 && LogInstance().SetCategoryLogLevel(toks[0], toks[1]))) {
-                    InitWarning(strprintf(_("Unsupported category-specific logging level -loglevel=%s. Expected -loglevel=<category>:<loglevel>"), level_str));
+                    InitWarning(strprintf(_("Unsupported category-specific logging level -loglevel=%s. Expected -loglevel=<category>:<loglevel>. Valid loglevel values: %s."), level_str, LogInstance().LogLevelsString()));
                 }
             }
         }
diff --git a/src/logging.cpp b/src/logging.cpp
index 3891be1cdc..964eb57eb8 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -321,9 +321,10 @@ std::vector<LogCategory> BCLog::Logger::LogCategoriesList() const
     return ret;
 }
 
-static constexpr std::array<BCLog::Level, static_cast<size_t>(BCLog::Level::None)> LogLevelsList()
+/** Log severity levels that can be selected by the user. */
+static constexpr std::array<BCLog::Level, 3> LogLevelsList()
 {
-    return {BCLog::Level::Trace, BCLog::Level::Debug, BCLog::Level::Info, BCLog::Level::Warning, BCLog::Level::Error};
+    return {BCLog::Level::Info, BCLog::Level::Debug, BCLog::Level::Trace};
 }
 
 std::string BCLog::Logger::LogLevelsString() const
@@ -492,7 +493,7 @@ void BCLog::Logger::ShrinkDebugFile()
 bool BCLog::Logger::SetLogLevel(const std::string& level_str)
 {
     const auto level = GetLogLevel(level_str);
-    if (!level) return false;
+    if (!level || level > BCLog::Level::Info) return false;
     m_log_level = level.value();
     return true;
 }
@@ -503,7 +504,7 @@ bool BCLog::Logger::SetCategoryLogLevel(const std::string& category_str, const s
     if (!GetLogCategory(flag, category_str)) return false;
 
     const auto level = GetLogLevel(level_str);
-    if (!level) return false;
+    if (!level || level > BCLog::Level::Info) return false;
     m_category_log_levels[flag] = level.value();
     return true;
 }
diff --git a/src/logging.h b/src/logging.h
index 88e5486545..6d4661792b 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -7,8 +7,8 @@
 #define BITCOIN_LOGGING_H
 
 #include <fs.h>
-#include <tinyformat.h>
 #include <threadsafety.h>
+#include <tinyformat.h>
 #include <unordered_map>
 #include <util/string.h>
 
@@ -191,7 +191,7 @@ namespace BCLog {
         std::string LogLevelsString() const;
 
         //! Returns the string representation of a log level.
-        std::string LogLevelToStr(BCLog::Level level = DEFAULT_LOG_LEVEL) const;
+        std::string LogLevelToStr(BCLog::Level level) const;
 
         bool DefaultShrinkDebugFile() const;
     };
diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp
index c3b4a8a8c1..87bd4ef114 100644
--- a/src/test/logging_tests.cpp
+++ b/src/test/logging_tests.cpp
@@ -171,18 +171,18 @@ BOOST_FIXTURE_TEST_CASE(logging_SeverityLevels, LogSetup)
 {
     LogInstance().EnableCategory(BCLog::LogFlags::ALL);
 
-    LogInstance().SetLogLevel(BCLog::Level::Info);
-    LogInstance().SetCategoryLogLevel(/*category_str=*/"net", /*level_str=*/"debug");
+    LogInstance().SetLogLevel(BCLog::Level::Debug);
+    LogInstance().SetCategoryLogLevel(/*category_str=*/"net", /*level_str=*/"info");
 
     // Global log level
     LogPrintLevel(BCLog::HTTP, BCLog::Level::Info, "foo1: %s\n", "bar1");
-    LogPrintLevel(BCLog::MEMPOOL, BCLog::Level::Debug, "foo2: %s. This log level is lower than the global one.\n", "bar2");
+    LogPrintLevel(BCLog::MEMPOOL, BCLog::Level::Trace, "foo2: %s. This log level is lower than the global one.\n", "bar2");
     LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Warning, "foo3: %s\n", "bar3");
     LogPrintLevel(BCLog::RPC, BCLog::Level::Error, "foo4: %s\n", "bar4");
 
     // Category-specific log level
     LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "foo5: %s\n", "bar5");
-    LogPrintLevel(BCLog::NET, BCLog::Level::Trace, "foo6: %s. This log level is lower than the category-specific one but higher than the global one. \n", "bar6");
+    LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "foo6: %s. This log level is the same as the global one but lower than the category-specific one, which takes precedence. \n", "bar6");
     LogPrintLevel(BCLog::NET, BCLog::Level::Error, "foo7: %s\n", "bar7");
 
     std::vector<std::string> expected = {
@@ -207,11 +207,11 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
         ResetLogger();
         ArgsManager args;
         args.AddArg("-loglevel", "...", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
-        const char* argv_test[] = {"bitcoind", "-loglevel=warning"};
+        const char* argv_test[] = {"bitcoind", "-loglevel=debug"};
         std::string err;
         BOOST_CHECK(args.ParseParameters(2, argv_test, err));
         init::SetLoggingLevel(args);
-        BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Warning);
+        BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Debug);
     }
 
     // Set category-specific log level
@@ -219,7 +219,7 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
         ResetLogger();
         ArgsManager args;
         args.AddArg("-loglevel", "...", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
-        const char* argv_test[] = {"bitcoind", "-loglevel=net:warning"};
+        const char* argv_test[] = {"bitcoind", "-loglevel=net:trace"};
         std::string err;
         BOOST_CHECK(args.ParseParameters(2, argv_test, err));
         init::SetLoggingLevel(args);
@@ -228,7 +228,7 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
         const auto& category_levels{LogInstance().CategoryLevels()};
         const auto net_it{category_levels.find(BCLog::LogFlags::NET)};
         BOOST_CHECK(net_it != category_levels.end());
-        BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Warning);
+        BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Trace);
     }
 
     // Set both global log level and category-specific log level
@@ -236,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
         ResetLogger();
         ArgsManager args;
         args.AddArg("-loglevel", "...", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
-        const char* argv_test[] = {"bitcoind", "-loglevel=debug", "-loglevel=net:warning", "-loglevel=http:error"};
+        const char* argv_test[] = {"bitcoind", "-loglevel=debug", "-loglevel=net:trace", "-loglevel=http:info"};
         std::string err;
         BOOST_CHECK(args.ParseParameters(4, argv_test, err));
         init::SetLoggingLevel(args);
@@ -247,11 +247,11 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
 
         const auto net_it{category_levels.find(BCLog::LogFlags::NET)};
         BOOST_CHECK(net_it != category_levels.end());
-        BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Warning);
+        BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Trace);
 
         const auto http_it{category_levels.find(BCLog::LogFlags::HTTP)};
         BOOST_CHECK(http_it != category_levels.end());
-        BOOST_CHECK_EQUAL(http_it->second, BCLog::Level::Error);
+        BOOST_CHECK_EQUAL(http_it->second, BCLog::Level::Info);
     }
 }

@jonatack jonatack force-pushed the loglevel-config-option branch from 3b777e3 to 63215dd Compare August 11, 2022 16:35
src/init/common.cpp Outdated Show resolved Hide resolved
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 63215dd

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and tested ACK 63215dd

I tried a few categories and global log levels and saw expected output in logs.

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crACK 63215dd

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 63215dd

LGTM

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the new log level Trace is unused outside of tests, is it assumed that some of the existent Debug log messages can/should be converted to Trace, or is it that just newly added logging will be using Trace?

Out of the scope of this PR: -debug= should be renamed to -log=, I guess, because now it could be confusing with the exposed levels. E.g. -debug=net -loglevel=net:info looks self-contradictory to me - is it going to log >=debug (due to -debug=net) or >=info due to loglevel=net:info?

src/logging.cpp Show resolved Hide resolved
src/init/common.cpp Outdated Show resolved Hide resolved
src/init/common.cpp Outdated Show resolved Hide resolved
src/logging.cpp Outdated Show resolved Hide resolved
src/logging.h Outdated Show resolved Hide resolved
src/test/logging_tests.cpp Outdated Show resolved Hide resolved
src/test/logging_tests.cpp Outdated Show resolved Hide resolved
src/test/logging_tests.cpp Outdated Show resolved Hide resolved
src/test/logging_tests.cpp Outdated Show resolved Hide resolved
doc/release-notes.md Outdated Show resolved Hide resolved
src/init/common.cpp Outdated Show resolved Hide resolved
@jonatack
Copy link
Member Author

jonatack commented Aug 16, 2022

Since the new log level Trace is unused outside of tests, is it assumed that some of the existent Debug log messages can/should be converted to Trace, or is it that just newly added logging will be using Trace?

Generally, the current debug messages become trace, LogPrint ones become debug, and LogPrintf ones become info, warning, or error (discussion in #25306). Edit: added this info to the pull description.

src/logging.h Outdated Show resolved Hide resolved
@jonatack jonatack force-pushed the loglevel-config-option branch from 63215dd to b99dc23 Compare August 16, 2022 16:23
@jonatack jonatack force-pushed the loglevel-config-option branch from 7aa7576 to 9580480 Compare August 20, 2022 11:41
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 9580480

@jonatack
Copy link
Member Author

@vasild, @dunxen, @brunoerg, @w0xlt, @jarolrod, @mzumsande, @klementtan mind having a last look here?

@maflcko
Copy link
Member

maflcko commented Aug 22, 2022

Given that this is primarily for devs, is there a reason to ship this in 24.0 this late before the feature freeze? (Sorry if this has been discussed before, haven't read the whole discussion)

@jonatack
Copy link
Member Author

jonatack commented Aug 22, 2022

Given that this is primarily for devs, is there a reason to ship this in 24.0 this late before the feature freeze? (Sorry if this has been discussed before, haven't read the whole discussion)

The reason is to unblock the parent PR that has been stuck on this step for months, during which it becomes increasingly harder to maintain due to changes merged in the codebase since, as there is logging throughout the codebase. I also see refactoring PRs merged right now with much less accumulated review. This PR has been carefully reworked not to change behavior. Merging would allow review to begin on the next steps in the parent and signal that this migration may realistically happen, which would encourage continued work and review.

@fanquake
Copy link
Member

The reason is to unblock the parent PR that has been stuck on this step for months, during which it becomes increasingly harder to maintain due to changes merged in the codebase since. I also see refactoring PRs merged right now with much less accumulated review. As this PR has been carefully reworked not to change behavior, it is like a refactoring.

If the parent PR isn't going into 24.0, it's not clear why this change would need to be merged into 24.0 to unblock it. In fact, it would seem better, if this (broader) migration is going to happen, to perform all the refactoring/changes within the same release cycle (i.e 25.0), rather than shipping some small part of it now, which has been massaged to not actually change any behaviour.

@jonatack
Copy link
Member Author

15 accumulated ACKs but maintainers not in favor. Up for grabs.

@jonatack jonatack closed this Aug 22, 2022
@maflcko
Copy link
Member

maflcko commented Aug 22, 2022

I am in favour of this configuration option, my question was solely about the milestone

@jonatack
Copy link
Member Author

jonatack commented Aug 22, 2022

Pushing this back needlessly only serves to stop momentum and discourage people from investing further time working on it or reviewing it. A lot of time and effort went into it to be ready for this release and unblock progress.

@jonatack
Copy link
Member Author

jonatack commented Aug 22, 2022

which has been massaged to not actually change any behaviour.

I think that was a needlessly negative comment. The changes were improvements, which is why I iterated on it, and there is no reason to change behavior yet for the few existing LogPrintLevel statements with a debug severity level.

@fanquake
Copy link
Member

I think that was a needlessly negative comment.

Apologies if you thought so. I was mostly referring to what you said here: "This PR has been carefully reworked not to change behavior.".

The changes were improvements,

I never said they weren't. My point was that this PR initially contained (iirc) more user-facing / behaviour changes; but was then altered to not change any behaviour (except for introducing a new option), seemingly so that it could be included for 24.0.

However it's still not clear (to me) why this needs to go into 24.0, especially if it's the first step in a larger (quite invasive) refactoring, which, as I mentioned above, I think if we are going to do, it would make more sense to do inside a single release cycle.

Also, there's review suggestions above, such as "Rename -loglevel to -log". If this is something we might do, then why rush to merge this now, only to have to change (and maybe go through deprecating) the option name again later, when we could instead just merge this change as -log for 25.0?

I understand that the parent PR might be unruly to maintain, but that's also to be expected if it's a major refactor, made up of a very large number of commits, that also touches many different areas of the codebase, including some of the most heavily trafficked (i.e p2p).

@jonatack
Copy link
Member Author

jonatack commented Aug 22, 2022

Work began on this on March 2 with #24464 and the goal was to have it done for v24. After an initial flurry, progress has been blocked at this step (and #25586 went nowhere). If we couldn't do it for v24 after an early start, the same will be given as a reason not to move forward with later steps 6 months from now for v25, and any progress would needlessly be pushed back and discouraged.

Also, there's review suggestions above, such as #25614 (review). If this is something we might do, then why rush to merge this now, only to have to change (and maybe go through deprecating) the option name again later, when we could instead just merge this change as -log for 25.0?

It's odd to read "rush to merge" for this pull along with its predecessor #25287, both opened in June and having quite a lot of review. Meanwhile, less-reviewed changes, often with fix-ups needed, are merged regularly without friction. The process looks arbitrary.

The suggestion you mention would only make sense if both (a) -debug were to be renamed to -log, and (b) the functionality of both -debug and -loglevel were to be combined. I am not sure there is consensus on doing both of those, nor on the resulting UX, and it's way out of scope here. Furthermore, there would be no need to create a deprecation process for a debug-only -loglevel option that would also not apply to renaming the established -debug option, if such a deprecation process exists; I have not seen one in the past years. Using hypotheticals like that as arguments to gatekeep this, with the number of ACKs and amount of review over two PRs (here and #25287) it has seen, doesn't make sense.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 9580480

(in case this gets reopened)

@klementtan
Copy link
Contributor

reACK 9580480

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 9580480

@jonatack jonatack deleted the loglevel-config-option branch August 22, 2022 20:57
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 9580480

@jonatack jonatack changed the title logging: add -loglevel configuration option and a trace log level Severity-based logging, step 2 Aug 29, 2022
@jonatack jonatack restored the loglevel-config-option branch August 29, 2022 14:57
@jonatack
Copy link
Member Author

Renamed and re-opened thanks to 5 re-ACKs (20 total), feature freeze postponed to Sept 1 per #24987 (comment), and numerous private messages of support (thank you).

@jonatack jonatack reopened this Aug 29, 2022
std::string BCLog::Logger::LogLevelsString() const
{
const auto& levels = LogLevelsList();
return Join(std::vector<BCLog::Level>{levels.begin(), levels.end()}, ", ", [this](BCLog::Level level) { return LogLevelToStr(level); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit in 9c7507b (only if you retouch and rebase for other reasons):

Can drop std::vector copy after c89fabf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will touch up in the parent (leaving unresolved until it's done).

@achow101 achow101 merged commit 7281fac into bitcoin:master Sep 1, 2022
@jonatack jonatack deleted the loglevel-config-option branch September 1, 2022 20:03
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 1, 2022
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some questions

@@ -55,6 +57,26 @@ void SetLoggingOptions(const ArgsManager& args)
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
}

void SetLoggingLevel(const ArgsManager& args)
{
if (args.IsArgSet("-loglevel")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check needed, given that you set DISALLOW_NEGATION and DISALLOW_ELISION?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks unnecessary to me, given that the entire body of the if is a for-loop that would iterate 0 times if this check is removed and -loglevel is not set, right? Is that true even if DISALLOW_ELISION is not used?

{
if (args.IsArgSet("-loglevel")) {
for (const std::string& level_str : args.GetArgs("-loglevel")) {
if (level_str.find_first_of(':', 3) == std::string::npos) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the 3 come from?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you ran SplitString first, this check could just be if (toks.size() == 1)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you ran SplitString first, this check could just be if (toks.size() == 1)?

Thanks, will touch up in the parent.

StdLockGuard scoped_lock(m_cs);
return m_category_log_levels;
}
void SetCategoryLogLevel(const std::unordered_map<LogFlags, Level>& levels)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really a fan of adding test-only code to the core codebase. This may live in the unit tests or test library.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will move it to the tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.