scripts and tools: update lint-logs.py to detect LogPrintLevel, mention WalletLogPrintf #25217

pull jonatack wants to merge 1 commits into bitcoin:master from jonatack:update-logs-linter-script-with-LogPrintLevel changing 1 files +2 −2
  1. jonatack commented at 9:54 PM on May 25, 2022: member

    Follow-up to #24464 that added the LogPrintLevel() macro.

    • update the lint-logs.py script to detect LogPrintLevel()
    • add WalletLogPrintf() (already detected but not mentioned) to the linter suggestion

    Example output:

    $ test/lint/lint-logs.py 
    All calls to LogPrintf(), LogPrint(), LogPrintLevel(), and WalletLogPrintf() should be terminated with "\n".
    
    src/addrdb.cpp:147:        LogPrintf("banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.", fs::quoted(fs::PathToString(m_banlist_dat)));
    src/addrman.cpp:388:        LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses", nLostUnk, nLost);
    src/banman.cpp:41:        LogPrintf("Recreating the banlist database");
    src/banman.cpp:66:    LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk  %dms", banmap.size(),
    src/banman.cpp:194:            LogPrint(BCLog::NET, "Removed banned node address/subnet: %s", sub_net.ToString());
    src/net.cpp:2092:                LogPrint(BCLog::NET, "Trying to make an anchor connection to %s", addrConnect.ToString());
    src/net.cpp:2408:        LogPrintLevel(BCLog::Level::Error, BCLog::NET, "%s", strError.original);
    src/net.cpp:2416:        LogPrintf("%s", strError.original);
    src/net.cpp:2432:            LogPrintf("%s", strError.original);
    src/net.cpp:2453:        LogPrintLevel(BCLog::Level::Error, BCLog::NET, "%s", strError.original);
    src/netbase.cpp:573:                LogPrintf("wait for connect to %s failed: %s",
    src/netbase.cpp:578:                LogPrint(BCLog::NET, "connection attempt to %s timed out", addrConnect.ToString());
    src/netbase.cpp:590:                LogPrintf("getsockopt() for %s failed: %s", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
    src/wallet/wallet.cpp:186:    wallet->WalletLogPrintf("Releasing wallet");
    src/wallet/wallet.cpp:1809:        WalletLogPrintf("Rescan completed in %15dms", duration_milliseconds.count());
    
  2. DrahtBot added the label Tests on May 25, 2022
  3. in test/lint/lint-logs.py:19 in 3475fca8ad outdated
      15 | @@ -16,12 +16,12 @@
      16 |  
      17 |  
      18 |  def main():
      19 | -    logs_list = check_output(["git", "grep", "--extended-regexp", r"LogPrintf?\(", "--", "*.cpp"], universal_newlines=True, encoding="utf8").splitlines()
      20 | +    logs_list = check_output(["git", "grep", "--extended-regexp", r"LogPrintLevel|LogPrintf?\(", "--", "*.cpp"], universal_newlines=True, encoding="utf8").splitlines()
    


    laanwj commented at 6:27 AM on May 26, 2022:

    Does the | in this regexp work without () context? (I don't see how)


    jonatack commented at 9:15 AM on May 26, 2022:

    It's working well for me with Python 3.10.4 (thanks for reviewing!) I didn't find how to have this work in another way but happy to update with a suggestion.

    $ test/lint/lint-logs.py 
    All calls to LogPrintf(), LogPrint(), and LogPrintLevel() should be terminated with "\n".
    
    src/net.cpp:2408:        LogPrintLevel(BCLog::Level::Error, BCLog::NET, "%s", strError.original);
    src/net.cpp:2416:        LogPrintf("%s", strError.original);
    src/net.cpp:2425:            LogPrintf("%s", strError.original);
    src/net.cpp:2432:            LogPrintf("%s", strError.original);
    src/net.cpp:2453:        LogPrintLevel(BCLog::Level::Error, BCLog::NET, "%s", strError.original);
    src/netbase.cpp:573:                LogPrintf("wait for connect to %s failed: %s",
    src/netbase.cpp:578:                LogPrint(BCLog::NET, "connection attempt to %s timed out", addrConnect.ToString());
    src/netbase.cpp:590:                LogPrintf("getsockopt() for %s failed: %s", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
    

    jonatack commented at 9:19 AM on May 26, 2022:

    A larger test and with WalletLogPrintf:

    $ test/lint/lint-logs.py 
    All calls to LogPrintf(), LogPrint(), and LogPrintLevel() should be terminated with "\n".
    
    src/addrdb.cpp:147:        LogPrintf("banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.", fs::quoted(fs::PathToString(m_banlist_dat)));
    src/addrman.cpp:388:        LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses", nLostUnk, nLost);
    src/banman.cpp:38:        LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets  %dms", m_banned.size(),
    src/banman.cpp:41:        LogPrintf("Recreating the banlist database");
    src/banman.cpp:66:    LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk  %dms", banmap.size(),
    src/banman.cpp:194:            LogPrint(BCLog::NET, "Removed banned node address/subnet: %s", sub_net.ToString());
    src/net.cpp:2092:                LogPrint(BCLog::NET, "Trying to make an anchor connection to %s", addrConnect.ToString());
    src/net.cpp:2408:        LogPrintLevel(BCLog::Level::Error, BCLog::NET, "%s", strError.original);
    src/net.cpp:2416:        LogPrintf("%s", strError.original);
    src/net.cpp:2425:            LogPrintf("%s", strError.original);
    src/net.cpp:2432:            LogPrintf("%s", strError.original);
    src/net.cpp:2453:        LogPrintLevel(BCLog::Level::Error, BCLog::NET, "%s", strError.original);
    src/netbase.cpp:573:                LogPrintf("wait for connect to %s failed: %s",
    src/netbase.cpp:578:                LogPrint(BCLog::NET, "connection attempt to %s timed out", addrConnect.ToString());
    src/netbase.cpp:590:                LogPrintf("getsockopt() for %s failed: %s", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
    src/wallet/wallet.cpp:186:    wallet->WalletLogPrintf("Releasing wallet");
    src/wallet/wallet.cpp:1809:        WalletLogPrintf("Rescan completed in %15dms", duration_milliseconds.count());
    

    Maybe we should mention WalletLogPrintf too. Edit: done and updated OP.


    laanwj commented at 11:45 AM on May 26, 2022:

    Yes but I mean I'd have expected (LogPrintLevel|LogPrintf?) otherwise it's not clear to the regexp parser what the outer boundary of the group is? Edit: it indeed works without grouping, however, what it seems to do is take the whole regexp (including the terminating \() as the group, which is not what you intend here as it'll also match occurences of LogPrintLevel without opening brace.


    jonatack commented at 12:45 PM on May 26, 2022:

    Thank you! Tested and updated.

  4. jonatack force-pushed on May 26, 2022
  5. jonatack renamed this:
    scripts and tools: update lint-logs.py with LogPrintLevel()
    scripts and tools: update lint-logs.py to detect LogPrintLevel, mention WalletLogPrintf
    on May 26, 2022
  6. laanwj commented at 12:56 PM on May 26, 2022: member

    LGTM now, this could be squashed to one commit imo.

  7. scripts and tools: update lint-logs.py to detect LogPrintLevel()
    and add WalletLogPrintf() (already detected) to the lint-logs.py suggestion
    
    Co-authored-by: laanwj <126646+laanwj@users.noreply.github.com>
    75848ec2da
  8. jonatack force-pushed on May 26, 2022
  9. jonatack commented at 1:01 PM on May 26, 2022: member

    Yes, squashed.

  10. laanwj commented at 1:12 PM on May 26, 2022: member

    ACK 75848ec2daa43b648cf497c59924d389e8243320

  11. DrahtBot commented at 12:51 AM on May 27, 2022: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25203 (log: dedup categories, add macro, use severity-based logging for tor/i2p/netbase by jonatack)

    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.

  12. MarcoFalke merged this on May 27, 2022
  13. MarcoFalke closed this on May 27, 2022

  14. jonatack deleted the branch on May 27, 2022
  15. sidhujag referenced this in commit 4c9c5997a7 on May 28, 2022
  16. DrahtBot locked this on May 27, 2023

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: 2026-04-14 21:13 UTC

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