Skip to content

Conversation

@jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Apr 4, 2017

Adds an RPC to get/set active logging categories.

First commit allows all categories except libevent to be reconfigured during runtime.
Second commit modifies InitHTTPServer() to allow leveldb logging to be reconfigured during runtime.

@jnewbery jnewbery changed the title [rpc Add logging rpc [rpc] Add logging rpc Apr 4, 2017
Copy link
Member

@laanwj laanwj Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this! This existed for a reason. What you did will reduce libevent performance extremely by always enabling their internal debugging. Same is probably true for leveldb. I'd prefer just not to allow to switch those at runtime.
(unless it can be done in a thread-safe way later on, but I don't think so)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I've tested this and logging is only enabled when libevent is built in debug mode:

https://github.com/libevent/libevent/blob/2e52bace9f9998826bd3819af328efc8d18decf9/log-internal.h#L46

and

https://github.com/libevent/libevent/blob/2e52bace9f9998826bd3819af328efc8d18decf9/log-internal.h#L86

I would have thought that if we're running libevent in debug, then performance is already hosed.

If I'm wrong, I left this as a separate commit so we can leave it out if needed. The first commit forbids trying to change libevent logging during runtime and stands on its own.

leveldb: #9999 always hands a logging class to leveldb at startup, even if logging is disabled. I don't know if that affects performance. This PR doesn't change that behaviour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible to compile libevent wholesale without debug messages. However, most distributions enable them.
Even if it is compiled with debug messages, normally they just sink at the libevent side before even being formatted: https://github.com/libevent/libevent/blob/master/log-internal.h#L80
Remember that libevent debugging is extremely noisy. It always is - the mask is currently unused - there are no specific flags.
There will be significant overhead to dropping the messages at our side, after formatting. That's worth it for the questionable advantage of being able to enable it during runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out libevent logging can be changed at runtime: https://github.com/libevent/libevent/blob/2e52bace9f9998826bd3819af328efc8d18decf9/whatsnew-2.1.txt#L269

I've pushed a new commit that leaves InitHTTPServer() unchanged and uses event_enable_debug_logging() to update logging.

@laanwj
Copy link
Member

laanwj commented Apr 5, 2017

Concept ACK ofcourse

@jonasschnelli
Copy link
Contributor

Oh. That's great.
Concept ACK. Will test soon.

@jnewbery
Copy link
Contributor Author

jnewbery commented Apr 6, 2017

Pushed a new commit that I hope addresses @laanwj's point here: #10150 (comment)

src/rpc/misc.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this code is almost duplicated with the exclude case (except the |/& and true/false). Might make sense to roll this into a function that converts a list of flag strings into a bitmask and apply that wholesale.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds sensible. Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, thanks, much better

@jnewbery jnewbery force-pushed the logging_rpc branch 3 times, most recently from 0f927ff to bc3ad60 Compare April 7, 2017 19:41
src/rpc/misc.cpp Outdated
Copy link
Member

@laanwj laanwj Apr 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add this warning I'd suggest it be context-sensitive:

  • libevent logging is being updated
  • the libevent version is older than 2.1.1

Though you could also make it an error in that case! (e.g. make UpdateHTTPServerLogging return false and then raise a JSON exception here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried doing something like that, but it's a bit tricky:

  • we only want to raise an error if only libevent logging is changed (ie if the user wants to include or exclude "all", then we shouldn't throw an error simply because "all" includes libevent).
  • I've already applied the include/excude bitmasks by this point, and we need the before/after state to know whether to throw.

I'll see if I can come up with something sensible.

Copy link
Member

@laanwj laanwj Apr 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm perfectly fine with removing this warning from this pull and doing that later. I just don't think it should be added unconditionally.

I've already applied the include/excude bitmasks by this point, and we need the before/after state to know whether to throw.

Sure. if((before ^ after) & BCLog::LIBEVENT) would work :-) Though it's probably best to do the check inside UpdateHTTPServerLogging because there you have the previous state, the desired new state, and the libevent version information available.

we only want to raise an error if only libevent logging is changed

That's a good point, and indeed speaks for making it a warning instead.

@jnewbery jnewbery force-pushed the logging_rpc branch 2 times, most recently from 2832101 to df35edb Compare April 10, 2017 14:50
@jnewbery
Copy link
Contributor Author

Pushed an updated version that hopefully addresses @laanwj's comments. Changes:

  • UpdateHTTPServerLogging() is now called by InitHTTPServer(). This contains the #if LIBEVENT_VERSION_NUMBER >= 0x02010100 preprocessor logic to one place.
  • UpdateHTTPServerLogging() now removes the BCLog::LIBEVENT bit flag if the libevent version does not support debug logging. That means that a call to the logging RPC will return the correct value for libevent (0 if libevent logging is not supported).
  • the logging RPC will throw an error if:
    • the libevent version does not support debug logging; and
    • the user tries to update only the BCLog::LIBEVENT flag

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. One nit: I don't think this global flag should be changed here as a side-effect. Maybe move the "disable the flag in logCategories if this function returns false" logic outside the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, changed so that the caller updates the logCategories bitfield (happens in two places - InitHTTPServer() and the logging() rpc).

@laanwj
Copy link
Member

laanwj commented Apr 12, 2017

Tested ACK 7fd50c3

@laanwj laanwj merged commit 7fd50c3 into bitcoin:master Apr 12, 2017
laanwj added a commit that referenced this pull request Apr 12, 2017
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
@jnewbery jnewbery deleted the logging_rpc branch April 12, 2017 18:00
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 19, 2019
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
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 25, 2019
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:
bitcoin/bitcoin#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.
bitcoin/bitcoin#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
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Apr 6, 2020
f66e50e [Doc] Add logging RPC to release notes (random-zebra)
bf55911 allow libevent logging to be updated during runtime (random-zebra)
ec43b51 Set BCLog::LIBEVENT correctly for old libevent versions. (random-zebra)
cbaf724 [rpc] Add logging rpc (random-zebra)

Pull request description:

  Implemented on top of:
  - [x] #1449
  - [x] #1437
  - [x] #1439
  - [x] #1450

  Backports bitcoin#10150

  > Adds an RPC to get/set active logging categories.
  First commit allows all categories except libevent to be reconfigured during runtime.
  Second commit modifies InitHTTPServer() to allow leveldb logging to be reconfigured during runtime.

ACKs for top commit:
  furszy:
    Really nice 👍 , ACK f66e50e .
  Fuzzbawls:
    ACK f66e50e

Tree-SHA512: 7b735628d341fb8661eb76f57dadc78e69ea63c62edb778450b3d9e3b7137ce06e08ceab835967b923401a9687e5b2605722a9f256e6ed85fc372a0e46086b8f
jonspock pushed a commit to jonspock/devault that referenced this pull request Oct 1, 2020
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:
bitcoin/bitcoin#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.
bitcoin/bitcoin#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
jonspock pushed a commit to jonspock/devault that referenced this pull request Oct 5, 2020
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:
bitcoin/bitcoin#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.
bitcoin/bitcoin#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
jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Oct 10, 2020
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:
bitcoin/bitcoin#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.
bitcoin/bitcoin#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
@rebroad
Copy link
Contributor

rebroad commented Apr 28, 2021

The help message could IMHO make it clearer how to enable and disable logging. I've tried "logging exclude estimatefee", "logging estimatefee false", "logging estimatefee exclude", and they all give a "Error parsing JSON" error.

Is it possible to toggle logging from the console?

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants