log: use error level for critical log messages #30255

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2406-logError changing 5 files +14 −14
  1. maflcko commented at 3:03 pm on June 9, 2024: member

    This picks up the first commit from #29231, but extends it to also cover cases that were missed in it.

    As per https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#logging, LogError should be used for severe problems that require the node to shut down.

  2. DrahtBot commented at 3:03 pm on June 9, 2024: contributor

    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
    ACK stickies-v, kevkevinpal, achow101
    Stale ACK BrandonOdiwuor

    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:

    • #29641 (scripted-diff: Use LogInfo/LogDebug over LogPrintf/LogPrint by maflcko)

    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.

  3. DrahtBot added the label Utils/log/libs on Jun 9, 2024
  4. maflcko force-pushed on Jun 9, 2024
  5. maflcko force-pushed on Jun 9, 2024
  6. maflcko requested review from stickies-v on Jun 10, 2024
  7. in src/validation.cpp:5523 in b90f1c36ff outdated
    5519@@ -5520,7 +5520,7 @@ Chainstate& ChainstateManager::InitializeChainstate(CTxMemPool* mempool)
    5520     const bool destroyed = DestroyDB(path_str);
    5521 
    5522     if (!destroyed) {
    5523-        LogPrintf("error: leveldb DestroyDB call failed on %s\n", path_str);
    5524+        LogError("[snapshot] leveldb DestroyDB call failed on %s\n", path_str);
    


    stickies-v commented at 10:15 am on June 10, 2024:
    I don’t think this should be LogError as this can be recovered from, e.g. here. Ideally, we just return error messages here and let the callsite log - but barring that I’d just leave as is since all the call sites that do lead to node termination will already log on the error level?

    maflcko commented at 10:42 am on June 10, 2024:
    Good point, deferred for the follow-up that handles warnings.
  8. in src/validation.cpp:6306 in b90f1c36ff outdated
    6302@@ -6303,7 +6303,7 @@ bool ChainstateManager::ValidatedSnapshotCleanup()
    6303                                    fs::path p_old,
    6304                                    fs::path p_new,
    6305                                    const fs::filesystem_error& err) {
    6306-        LogPrintf("Error renaming path (%s) -> (%s): %s\n",
    6307+        LogError("[snapshot] Error renaming path (%s) -> (%s): %s\n",
    


    stickies-v commented at 10:17 am on June 10, 2024:
    nit: since we’re calling GetNotifications().fatalError() next, I think this log line can just be removed?

    maflcko commented at 10:39 am on June 10, 2024:
    My understanding is that the notification does not include err.what(), so the debug log in this line is still needed.

    stickies-v commented at 11:03 am on June 10, 2024:

    Can’t we just merge them?

     0diff --git a/src/validation.cpp b/src/validation.cpp
     1index 89aa84a551..ac95824443 100644
     2--- a/src/validation.cpp
     3+++ b/src/validation.cpp
     4@@ -6303,12 +6303,10 @@ bool ChainstateManager::ValidatedSnapshotCleanup()
     5                                    fs::path p_old,
     6                                    fs::path p_new,
     7                                    const fs::filesystem_error& err) {
     8-        LogError("[snapshot] Error renaming path (%s) -> (%s): %s\n",
     9-                  fs::PathToString(p_old), fs::PathToString(p_new), err.what());
    10         GetNotifications().fatalError(strprintf(_(
    11-            "Rename of '%s' -> '%s' failed. "
    12+            "[snapshot] Rename of '%s' -> '%s' failed: %s. "
    13             "Cannot clean up the background chainstate leveldb directory."),
    14-            fs::PathToString(p_old), fs::PathToString(p_new)));
    15+            fs::PathToString(p_old), fs::PathToString(p_new), err.what()));
    16     };
    17 
    18     try {
    

    maflcko commented at 3:11 pm on June 10, 2024:
    I think it is fine to have this log, but happy to review a separate pull removing it :)

    maflcko commented at 3:12 pm on June 10, 2024:
    This reminded me to change the two other log lines before fatalError to use the error level. So I pushed that other change in the last push.
  9. stickies-v approved
  10. stickies-v commented at 10:33 am on June 10, 2024: contributor
    ACK b90f1c36ff0e469bc64830ff35e591a9aab63fb2 - more consistent logging
  11. maflcko force-pushed on Jun 10, 2024
  12. maflcko force-pushed on Jun 10, 2024
  13. stickies-v commented at 11:25 am on June 10, 2024: contributor
    re-ACK 2222f2573c8de0a7f7171e6fc9e844ad448e1f65
  14. log: use error level for critical log messages
    As per doc/developer-notes#logging, LogError should be used for
    severe problems that require the node to shut down.
    
    Co-Authored-By: stickies-v <stickies-v@protonmail.com>
    fae3a1f006
  15. BrandonOdiwuor approved
  16. BrandonOdiwuor commented at 1:01 pm on June 10, 2024: contributor
    ACK 2222f2573c8de0a7f7171e6fc9e844ad448e1f65 - Replacing LogPrintf with Logerror to enhance critical error logging
  17. maflcko force-pushed on Jun 10, 2024
  18. DrahtBot added the label CI failed on Jun 10, 2024
  19. stickies-v commented at 11:15 am on June 11, 2024: contributor
    re-ACK fae3a1f0065064d80ab4c0375a9eaeb666c5dd55, I’m ~0 on the latest force push as user_error was already logged at the right level through GetNotifications().fatalError(user_error); so I’d be in favour of deduplicating/cleaning up this logging logic but can be done in follow-up.
  20. DrahtBot requested review from BrandonOdiwuor on Jun 11, 2024
  21. DrahtBot removed the label CI failed on Jun 12, 2024
  22. maflcko commented at 9:14 am on June 12, 2024: member

    user_error was already logged at the right level through GetNotifications().fatalError(user_error);

    Happy to review a follow-up for the two cases (https://github.com/bitcoin/bitcoin/pull/30255#discussion_r1633421463). For now I think it is risk-free and more consistent to log the fatal error twice in the error log category.

  23. kevkevinpal commented at 0:57 am on June 14, 2024: contributor

    ACK fae3a1f

    agree with #30255 (review) but that should be good for a follow up

  24. achow101 commented at 6:23 pm on June 14, 2024: member
    ACK fae3a1f0065064d80ab4c0375a9eaeb666c5dd55
  25. achow101 merged this on Jun 14, 2024
  26. achow101 closed this on Jun 14, 2024

  27. maflcko deleted the branch on Jun 21, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-03 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me