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

logging: Update to new logging API #29231

Closed
wants to merge 6 commits into from

Conversation

ajtowns
Copy link
Contributor

@ajtowns ajtowns commented Jan 11, 2024

Updates various logging calls to the new API from #28318. All commits are scripted diffs, so should be easy to update if needed, and also easy to reuse the scripts to update other code if needed when rebasing it after this is merged. Changes all uses of LogPrintLevel() where the level is hardcoded, and changes all LogPrintf and LogPrint uses in init.cpp.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 11, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK fanquake
Stale ACK stickies-v, davidgumberg

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29975 (blockstorage: Separate reindexing from saving new blocks by mzumsande)
  • #29700 (kernel, refactor: return error status on all fatal errors by ryanofsky)
  • #29641 (scripted-diff: Use LogInfo/LogDebug over LogPrintf/LogPrint by maflcko)
  • #28830 ([refactor] Check CTxMemPool options in ctor by TheCharlatan)
  • #28765 (p2p: Fill reconciliation sets (Erlay) by naumenkogs)
  • #28676 ([WIP] Cluster mempool implementation by sdaftuar)
  • #27826 (validation: log which peer sent us a header by Sjors)
  • #26022 (Add util::ResultPtr class by ryanofsky)
  • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
  • #25665 (refactor: Add util::Result failure values, multiple error and warning messages by ryanofsky)

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.

@ajtowns
Copy link
Contributor Author

ajtowns commented Jan 11, 2024

Depending on how many conflicts drahtbot detects, maybe this should be targeting a merge around 27.0's feature freeze?

Many of the log statements in init.cpp could be done at a better level, eg LogPrintf("Error: Out of memory. Terminating.\n"); should obviously be logging at the "error" level, not the "info" level. In order to keep this PR scripted-diff only, I won't fix that here; but it can fixed in an independent PR either before or after this PR is merged.

@jonatack
Copy link
Contributor

I don't think updating all the macros is a good idea until the API is finished.

@fanquake
Copy link
Member

fanquake commented Jan 11, 2024

Concept ACK - only 3 conflicts, and none look like priority projects.

@@ -2626,7 +2626,7 @@ bool Chainstate::FlushStateToDisk(
// TODO: Handle return error, or add detailed comment why it is
// safe to not return an error upon failure.
if (!m_blockman.FlushChainstateBlockFile(m_chain.Height())) {
LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Warning, "%s: Failed to flush block file.\n", __func__);
LogWarning("%s: Failed to flush block file.\n", __func__);
Copy link
Member

Choose a reason for hiding this comment

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

Can remove the useless __func__ when changing the log output anyway?

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

ACK 2632d03

Since we don't have significant merge conflicts I would this support this PR having a non-scripted diff commit to first fix incorrect levels (instead of having to fix and then re-fix) but am okay with this approach too.

Suggested fixes in master...stickies-v:bitcoin:2024-01/fix-log-level-29231 - happy to open a separate pull for it too?

@maflcko
Copy link
Member

maflcko commented Jan 15, 2024

happy to open a separate pull for it too?

Yeah, I think it is better to change a line of code only once, instead of twice, unless there is a reason to change it twice.

@ajtowns
Copy link
Contributor Author

ajtowns commented Jan 16, 2024

Suggested fixes in master...stickies-v:bitcoin:2024-01/fix-log-level-29231 - happy to open a separate pull for it too?

Added these commits

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

ACK 1441ab7

@ajtowns
Copy link
Contributor Author

ajtowns commented Feb 1, 2024

Rebased

@epiccurious
Copy link

Changes all uses of LogPrintLevel() where the level is hardcoded, and changes all LogPrintf and LogPrint uses in init.cpp.

Trying to understand the concept here. What problem does this solve?

@stickies-v
Copy link
Contributor

re-ACK 8d46bd6 - no change since 1441ab7 except for addressing merge conflicts

src/init.cpp Outdated Show resolved Hide resolved
@davidgumberg
Copy link
Contributor

davidgumberg commented Apr 12, 2024

utACK 8d46bd6

Tangential to this PR:
Is LogPrintLevel in void libevent_log_cb(...) an example of:

"when [...] a category needs to be added for an info/warning/error log message"

Otherwise:
 static void libevent_log_cb(int severity, const char *msg)
 {
-    BCLog::Level level;
     switch (severity) {
     case EVENT_LOG_DEBUG:
-        level = BCLog::Level::Debug;
+        LogDebug(BCLog::LIBEVENT, "%s\n", msg);
         break;
     case EVENT_LOG_MSG:
-        level = BCLog::Level::Info;
+        LogInfo("%s\n", msg);
         break;
     case EVENT_LOG_WARN:
-        level = BCLog::Level::Warning;
+        LogWarning("%s\n", msg);
         break;
     default: // EVENT_LOG_ERR and others are mapped to error
-        level = BCLog::Level::Error;
+        LogError("%s\n", msg);
         break;
     }
-    LogPrintLevel(BCLog::LIBEVENT, level, "%s\n", msg);
 }

stickies-v and others added 6 commits April 28, 2024 10:23
As per doc/developer-notes#logging, LogError should be used for
severe problems that require the node to shut down
As per doc/developer-notes#logging, LogWarning should be used for
severe problems that do not warrant shutting down the node
-BEGIN VERIFY SCRIPT-
sed -i 's/LogPrintLevel(\(BCLog::[^,]*\), BCLog::Level::Debug,/LogDebug(\1,/' src/net_processing.cpp src/dbwrapper.cpp src/net.cpp src/node/txreconciliation.cpp src/validation.cpp
-END VERIFY SCRIPT-
Changes log output from:

  [net:error] Something bad happened

to either

  [error] Something bad happened

or, when -loglevelalways=1 is enabled:

  [all:error] Something bad happened

-BEGIN VERIFY SCRIPT-
sed -i 's/LogPrintLevel(\(BCLog::[^,]*\), BCLog::Level::Error, */LogError(/' src/net.cpp src/txdb.cpp src/txmempool.cpp
-END VERIFY SCRIPT-
Changes log output from:

  [net:warning] Something problematic happened

to either

  [warning] Something problematic happened

or, when -loglevelalways=1 is enabled:

  [all:warning] Something problematic happened

-BEGIN VERIFY SCRIPT-
sed -i 's/LogPrintLevel(\(BCLog::[^,]*\), BCLog::Level::Warning, */LogWarning(/' src/net.cpp src/node/blockstorage.cpp src/validation.cpp
-END VERIFY SCRIPT-
-BEGIN VERIFY SCRIPT-
sed -i 's/LogPrint(\(BCLog::[^,]*\),/LogDebug(\1,/' src/init.cpp
sed -i 's/LogPrintf(/LogInfo(/' src/init.cpp
-END VERIFY SCRIPT-
@ajtowns
Copy link
Contributor Author

ajtowns commented Apr 28, 2024

Rebased over #28834, removed redundancy from LogWarning("Warning: ..")

@laanwj
Copy link
Member

laanwj commented Apr 30, 2024

@ajtowns Sorry, i didn't mean to derail this, i shouldn't have commented.

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

Successfully merging this pull request may close these issues.

None yet

9 participants