Fixes #21058
As the LogPrint
macro takes the debug log category as parameter, I think it would be nice to have that debug log category also shown together with the according debug log message, to have clear transparency what debug message belongs to what debug category.
In the past, people inserted the same debug log category name in the message itself, e.g.
torcontrol.cpp: LogPrint(BCLog::TOR, "tor: SAFECOOKIE authentication challenge successful\n");
With this patch, this would be obsolete, and I would be willing to create a follow-up PR to cleanup that redundancy those then-redundant in-message categories are removed.
Here is a log example how the log looks with this patch and debug=1
:
02021-02-07T15:45:55Z [leveldb] WriteBatch memory usage: db=index, before=0.0MiB, after=0.0MiB
12021-02-07T15:45:55Z [bench] FlushStateToDisk: write block index to disk completed (12.27ms)
22021-02-07T15:45:55Z FlushStateToDisk: write coins cache to disk (69 coins, 11kB) started
32021-02-07T15:45:55Z [coindb] Writing final batch of 0.00 MiB
42021-02-07T15:45:55Z [leveldb] WriteBatch memory usage: db=chainstate, before=0.0MiB, after=0.0MiB
52021-02-07T15:45:55Z [coindb] Committed 0 changed transaction outputs (out of 69) to coin database...
62021-02-07T15:45:55Z FlushStateToDisk: write coins cache to disk (69 coins, 11kB) completed (0.00s)
72021-02-07T15:45:55Z [validation] Enqueuing ChainStateFlushed: block hash=0000000000000025d3499369d144977b6266bac92837748dc452e84cd05bc007
82021-02-07T15:45:55Z [validation] ChainStateFlushed: block hash=0000000000000025d3499369d144977b6266bac92837748dc452e84cd05bc007
92021-02-07T15:45:55Z [bench] FlushStateToDisk: write block and undo data to disk started
102021-02-07T15:45:55Z [bench] FlushStateToDisk: write block and undo data to disk completed (15.44ms)
112021-02-07T15:45:55Z [bench] FlushStateToDisk: write block index to disk started
122021-02-07T15:45:55Z [leveldb] WriteBatch memory usage: db=index, before=0.0MiB, after=0.0MiB
132021-02-07T15:45:55Z [bench] FlushStateToDisk: write block index to disk completed (8.10ms)
142021-02-07T15:45:55Z FlushStateToDisk: write coins cache to disk (0 coins, 0kB) started
152021-02-07T15:45:55Z [coindb] Writing final batch of 0.00 MiB
162021-02-07T15:45:55Z [leveldb] WriteBatch memory usage: db=chainstate, before=0.0MiB, after=0.0MiB
172021-02-07T15:45:55Z [coindb] Committed 0 changed transaction outputs (out of 0) to coin database...
182021-02-07T15:45:55Z FlushStateToDisk: write coins cache to disk (0 coins, 0kB) completed (0.00s)
192021-02-07T15:45:55Z [validation] Enqueuing ChainStateFlushed: block hash=0000000000000025d3499369d144977b6266bac92837748dc452e84cd05bc007
202021-02-07T15:45:55Z Shutdown: done
212021-02-07T15:45:55Z [qt] GUI: shutdown : Shutdown finished
I tested also with setting debug=addrman
and it works, only debug log messages of category addrman
are logged then, with the prefix.
I think this is a step for the better and there is no drawback. I think there should be a better logging with pairing of log category and log level (e.g. like in Tor log), but that should be out of the scope of this PR.
I have read the developer notes, and because of section “Source code organization” I extra included the #include <map>
in logging.cpp
allthough it was not needed to successfully compile.
Unfortunately, I am no C++ expert and I guess there are chances that the places/scope of the definitions may be not optimal.
Any help for doing better is appreciated.
I saw the need to clone the function LogCategoryPrintf
because I had not seen a way to change __VA_ARGS__
to insert the log category string in the beginning of the first (format string) parameter.
I have allowed edits by maintainers, too, your are welcome to edit.