HomePhabricator

[Chronik] Add `log!` and `log_chronik!` macros

Description

[Chronik] Add log! and log_chronik! macros

Summary:

  1. Add CHRONIK log category to BCLog
  2. Split log_println into log_print (logs unconditionally) and log_print_chronik (logs to category BCLog::CHRONIK)
  3. Add chronik-util crate
  4. Add log! (calls log_print) and log_chronik! macro (calls log_print_chronik)

Note: There is no (built-in) equivalent to the __FUNC__ macro in Rust, so we just put <chronik unknown> there. Capturing the current function name is possible but requires a bit of a hack (see https://stackoverflow.com/a/40234666).

Note: __FILE__ in C++ is relative to cwd (e.g. build), but file!() in Rust is relative to /. We haven't spent any time harmonizing this, as this is sufficient for debugging purposes.

Test Plan:

  1. ninja
  2. ./src/bitcoind -help: Under -debug option, it lists chronik
  3. ./src/bitcoind -regtest: Still logs (only) "Starting Chronik..." as before
  4. ./src/bitcoind -regtest -debug=chronik: Now also logs "Note: Chronik is not implemented yet. These logs are just for testing."
  5. ./src/bitcoind -regtest -debug=chronik -logsourcelocations: Logs:
[chronik/chronik-lib/src/bridge.rs:11] [<chronik unknown>] Starting Chronik...
[chronik/chronik-lib/src/bridge.rs:12] [<chronik unknown>] Note: Chronik is not implemented yet. These logs are just for testing.

Reviewers: Fabien, #bitcoin_abc

Reviewed By: Fabien, #bitcoin_abc

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

Details

Provenance
tobias_ruckAuthored on Sep 21 2022, 16:52
tobias_ruckPushed on Sep 22 2022, 11:37
Reviewer
Restricted Project
Differential Revision
D12026: [Chronik] Add `log!` and `log_chronik!` macros
Parents
rABCb34f982ea773: [avalanche] Fix an abc_p2p_proof_inventory flakiness
Branches
Unknown
Tags
Unknown