HomePhabricator

[rpc] Add logging RPC

Description

[rpc] Add logging RPC

Summary:
PR10150:
7fd50c3 allow libevent logging to be updated during runtime (John Newbery)
5255aca [rpc] Add logging RPC (John Newbery)
4d9950d Set BCLog::LIBEVENT correctly for old libevent versions. (John Newbery)

Tree-SHA512: d6788a7205372c0528da71eca052910dfb055f2940ca884f422ff3db66e23a2b49c6a15b8f27d5255554fe5c5a928f5dd903fdc63b0bd6c8fa7783e77bb30fe8

Our logging code was refactored some time ago in a way that looks a lot like Core PR12954. Functionally, however, we are still behind in comparison to Core when their refactor occurred. That has made this backport very complicated. I have made comments on each change that directly link to the PR it was backported from to assist in review. As mentioned in the summary, some changes had to be modified to bridge the gap between the state of Core's logging code before and after the refactor in PR12954.

Backport of Core PR10150:
https://github.com/bitcoin/bitcoin/pull/10150/

As is, Core's logging code as seen in PR10150 is incompatible with our own logging code. I Also pulled the EnableOrDisableLogCategories() function and the updated libevent filter code and Logger::GetCategoryMask() function from Core PR12954 which is a refactor of Core's logging code that makes it more closely mirror our own.
https://github.com/bitcoin/bitcoin/pull/12954/

Test Plan:

make check
./bitcoind

./bitcoin-cli help

logging rpc should not show up in the list of commands.

./bitcoin-cli help logging

This should display logging rpc help

./bitcoin-cli logging

This should display the list of logging options all set to false (default).

./bitcoin-cli logging "[\"all"\"]
./bitcoin-cli getbestblockhash
check debug.log

The first line should output the list of logging options all set to true if your libevent version is at or above v2.1.1. Otherwise, every option except libevent will be set to true.
The second line should cause the logger to write some extra debug information to the debug.log file.

./bitcoin-cli logging "[]" "[\"all\"]"
./bitcoin-cli getbestblockhash
check debug.log

The first line should output the list of logging options all set to false again.
The second line should cause the logger to revert back to its original logging behavior, outputting no extra logging information to debug.log.

./bitcoin-cli logging "[\"libevent"\"]

If your version of libevent is below v2.1.1, you should receive an error stating libevent logging cannot be updated when using libevent before v2.1.1. If your libevent is version is at or above 2.1.1, then it should proceed as normal. Tested by changing line 431 in httpserver.cpp from #if LIBEVENT_VERSION_NUMBER >= 0x02010100 to #if LIBEVENT_VERSION_NUMBER < 0x02010100.

Reviewers: deadalnix, Fabien, jasonbcox, markblundeberg, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3464

Details

Provenance
John Newbery <john@johnnewbery.com>Authored on Apr 3 2017, 17:39
nakihitoCommitted on Oct 17 2019, 17:27
nakihitoPushed on Oct 17 2019, 18:23
Reviewer
Restricted Owners Package
Differential Revision
D3464: [rpc] Add logging RPC
Parents
rSTAGINGbbfb8effa8f8: Change CDnsSeedOpts to use std::string instead of c-strings
Branches
Unknown
Tags
Unknown