Page MenuHomePhabricator

Early logging improvements
ClosedPublic

Authored by Fabien on Wed, Nov 5, 14:12.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC3f84968a29c7: Early logging improvements
Summary
In order to cope gracefully with Log*() calls that are invoked prior to logging being fully configured (indicated by calling StartLogging() we buffer early log messages in m_msgs_before_open. This has a couple of minor issues:

 - if there are many such log messages the buffer can become arbitrarily large; this can be a problem for users of libkernel that might not wish to worry about logging at all, and as a result never invoke StartLogging()
 - early log messages are formatted before the formatting options are configured, leading to inconsistent output

Fix those issues by buffering the log info prior to formatting it, and setting a limit on the size of the buffer (dropping the oldest lines, and reporting the number of lines skipped).

Also adds some thread safety annotations, and the ability to invoke LogInstance().DisableLogging() if you want to disable logging entirely, for a minor efficiency improvement.

Backport of core#30386.

Includes a cherry-picked commit:
https://github.com/bitcoin/bitcoin/pull/28385/commits/79ce9f0aa46de8ff742be83fd6f68eab40e073ec

Depends on D18874.

Test Plan
ninja all check-all