Page MenuHomePhabricator

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

Authored by tobias_ruck on Sep 21 2022, 17:06.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCfe64c8585c3c: [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.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tobias_ruck edited the summary of this revision. (Show Details)
tobias_ruck edited the summary of this revision. (Show Details)
tobias_ruck edited the summary of this revision. (Show Details)
tobias_ruck edited the test plan for this revision. (Show Details)

Fix doc for log_chronik!

Fabien requested changes to this revision.Sep 21 2022, 18:51

This is missing the log.rs source file. Why is the build passing fine ?

This revision now requires changes to proceed.Sep 21 2022, 18:51

Rebased from *correct* master.

Somehow the previous diff was rebased from an incorrect master, possibly after an incorrect merge by arc land. What happened is
that log.rs somehow ended up in the previous commit (8c25edd, with a different hash). Phabricator then displayed only the last commit
(without log.rs)

This revision is now accepted and ready to land.Sep 22 2022, 07:08