Add a left-justified width field to log2_work component for a uniform debug.log output #19317

pull jamesgmorgan wants to merge 1 commits into bitcoin:master from jamesgmorgan:jmorgan-updatetipfmt changing 1 files +3 −3
  1. jamesgmorgan commented at 3:10 AM on June 18, 2020: contributor

    Motivation: It's jarring to watch the output of tail -f ~/btcdata/debug.log scroll by and very frequently see columns not lining up correctly because log2_work somtimes has less precision than 8 digits.

    Current display:

    2020-06-18T02:54:42Z UpdateTip: new best=0000000000000000107f877e4920643f9fb06090fa7551cd1cdd83b857f520aa height=382038 version=0x00000003 log2_work=83.558653 tx=90953616 date='2015-11-04T17:11:44Z' progress=0.166675 cache=117.6MiB(966410txo)
    2020-06-18T02:54:51Z UpdateTip: new best=0000000000000000019a4de585d30d1a8cc13c7a1972d11b4945635c9556acb5 height=382039 version=0x00000003 log2_work=83.55868 tx=90955936 date='2015-11-04T17:19:39Z' progress=0.166679 cache=117.9MiB(968799txo)
    

    Display with this commit:

    2020-06-18T02:54:42Z UpdateTip: new best=0000000000000000107f877e4920643f9fb06090fa7551cd1cdd83b857f520aa height=382038 version=0x00000003 log2_work=83.558653 tx=90953616 date='2015-11-04T17:11:44Z' progress=0.166675 cache=117.6MiB(966410txo)
    2020-06-18T02:54:51Z UpdateTip: new best=0000000000000000019a4de585d30d1a8cc13c7a1972d11b4945635c9556acb5 height=382039 version=0x00000003 log2_work=83.55868  tx=90955936 date='2015-11-04T17:19:39Z' progress=0.166679 cache=117.9MiB(968799txo)
    
  2. fanquake added the label Utils/log/libs on Jun 18, 2020
  3. practicalswift commented at 8:23 AM on June 18, 2020: contributor

    Concept ACK: as a pure Bitcoin Core console user (-printtoconsole is my interface) the unnecessary column jumping has annoyed me (mildly) for years :)

    It is easier to scan for anomalies if the column lengths don't vary unnecessarily.

    Warm welcome as a contributor @jamesgmorgan - nice small console UX improvement :)

    Possible alternative which will achieve precision to 6 places and thus remove the suggested left-justification (left-justification might theoretically break log parsers):

    diff --git a/src/validation.cpp b/src/validation.cpp
    index cbbc857fdcfc..971f19240e51 100644
    --- a/src/validation.cpp
    +++ b/src/validation.cpp
    @@ -1271,12 +1271,12 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
         if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork)
             pindexBestInvalid = pindexNew;
     
    -    LogPrintf("%s: invalid block=%s  height=%d  log2_work=%.8g  date=%s\n", __func__,
    +    LogPrintf("%s: invalid block=%s  height=%d  log2_work=%f  date=%s\n", __func__,
           pindexNew->GetBlockHash().ToString(), pindexNew->nHeight,
           log(pindexNew->nChainWork.getdouble())/log(2.0), FormatISO8601DateTime(pindexNew->GetBlockTime()));
         CBlockIndex *tip = chainActive.Tip();
         assert (tip);
    -    LogPrintf("%s:  current best=%s  height=%d  log2_work=%.8g  date=%s\n", __func__,
    +    LogPrintf("%s:  current best=%s  height=%d  log2_work=%f  date=%s\n", __func__,
           tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0),
           FormatISO8601DateTime(tip->GetBlockTime()));
         CheckForkWarningConditions();
    @@ -2245,7 +2245,7 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
                 DoWarning(strWarning);
             }
         }
    -    LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__, /* Continued */
    +    LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%f tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__, /* Continued */
           pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
           log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
           FormatISO8601DateTime(pindexNew->GetBlockTime()),
    

    Will give the output:

    2020-06-18T02:54:42Z UpdateTip: new best=0000000000000000107f877e4920643f9fb06090fa7551cd1cdd83b857f520aa height=382038 version=0x00000003 log2_work=83.558653 tx=90953616 date='2015-11-04T17:11:44Z' progress=0.166675 cache=117.6MiB(966410txo)
    2020-06-18T02:54:51Z UpdateTip: new best=0000000000000000019a4de585d30d1a8cc13c7a1972d11b4945635c9556acb5 height=382039 version=0x00000003 log2_work=83.558680 tx=90955936 date='2015-11-04T17:19:39Z' progress=0.166679 cache=117.9MiB(968799txo)
    
  4. laanwj commented at 9:54 AM on June 18, 2020: member

    Isn't there a way to always force 8 digits of precision? I'd slightly prefer appending 0 to space padding.

    Edit: oh, I only just read @practicalswift's post in detail, so just %f?

  5. theStack commented at 12:05 PM on June 18, 2020: member

    Concept ACK

  6. jamesgmorgan commented at 5:39 PM on June 18, 2020: contributor

    Really appreciate both the generous welcome and considered and swift responses - thank you 🙏

    On reflection, pad-by-0 rather than space is definitely a better refinement to the fix. @practicalswift if I could ask for guidance - would it be preferable if I made a new commit to update this PR or better to rebase+quash first (would be my inclination)?

  7. jonatack commented at 5:52 PM on June 18, 2020: member

    Concept ACK. Welcome @jamesgmorgan :) I think squash/force-push would be fine here.

  8. Change format of log2_work for uniform output (zero-padded) c858302280
  9. jamesgmorgan force-pushed on Jun 21, 2020
  10. practicalswift commented at 9:35 PM on June 21, 2020: contributor

    ACK c8583022800410afeb75e0154df7290d080d581d -- patch looks great :)

  11. achow101 commented at 10:39 PM on June 21, 2020: member

    ACK c8583022800410afeb75e0154df7290d080d581d

  12. laanwj commented at 2:02 PM on July 9, 2020: member

    Tested ACK c8583022800410afeb75e0154df7290d080d581d

  13. laanwj merged this on Jul 9, 2020
  14. laanwj closed this on Jul 9, 2020

  15. sidhujag referenced this in commit 7abd5f23e4 on Jul 9, 2020
  16. Fabcien referenced this in commit 7eb6c233b6 on May 28, 2021
  17. DrahtBot locked this on Feb 15, 2022

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-13 15:14 UTC

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