Page MenuHomePhabricator

logging: Add severity level to logs.
Needs ReviewPublic

Authored by PiRK on Wed, Nov 27, 21:14.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Overview: This PR introduces a new macro, LogPrintLevel, that allows developers to add logs with the severity level. Additionally, it will also print the log category if it is specified.

Sample log:

2022-03-04T16:41:15Z [opencon] [net:debug] trying connection XX.XX.XXX.XXX:YYYYY lastseen=2.7hrs

This is a backport of core#24464 and core#29419
https://github.com/bitcoin/bitcoin/pull/24464/commits/a8290649a6578df120a71c9493acdf071e010d96
https://github.com/bitcoin/bitcoin/pull/29419/commits/d3b3af90343b7671231afd7dff87e87ff86d31d7 (dedup category names and improve logging.cpp)
https://github.com/bitcoin/bitcoin/pull/24464/commits/e11cdc930375eaec8d737e116138b2f2018c099f

Test Plan

ninja all check-all

Event Timeline

PiRK requested review of this revision.Wed, Nov 27, 21:14
src/test/logging_tests.cpp
56–62

I have no clue about why we need to do this when Core does not need it. I checked the entire git history for logging.*, and didn't find anything that would explain why the logs are properly flushed for Core but not for Bitcoin ABC.

Without this, all these tests fail because tmp_log_path is still empty when we read it to look for the log lines.

src/logging.cpp
110

Unrelated to this diff: This one is unused, so if we ever need more log categories we could reuse the (1 << 8) slot