This is purely a refactor with no behavior changes.
This creates a new class BCLog::Logger to encapsulate all global logging configuration and state.
This is purely a refactor with no behavior changes.
This creates a new class BCLog::Logger to encapsulate all global logging configuration and state.
Concept ACK, splitting the logging functionality out of util makes sense, util.cpp is large, haphazard and this is a clearly distinguishable concern from the rest.
Concept ACK. Needs rebase
150 | - } \ 151 | -} while(0) 152 | -#endif 153 | - 154 | template<typename... Args> 155 | bool error(const char* fmt, const Args&... args)
I think this should move to logging as well, so the cyclic dependency between logging and util can be avoided.
LogPrintf is also used in TraceThread, and I don't think either of them actually belong in logging (the whole point of this PR is to create a more cohesive separation). I can very easily imagine another method that gets added to util.h in the future requiring logging as well.
The dependency isn't really cyclic -- logging.cpp includes util.h, and util.h includes logging.h, but logging.h does not include util.h.
My view is that you should always treat the .h and the .cpp file as one unit. While this may indeed not be a cyclic dependency for the compiler, it is certainly one between the two modules semantically: logging can't work without util, and util can't work without logging. Finding out why that is the case helps creating a cleaner separation.
You're right that util is going to depend on logging though, as it contains a number of higher level functions. However, It looks like logging only really needs util for finding the debug log path, though. All the rest is in utiltime. This seems easy to fix, by instead having init query the path and call a setter on logging for it for example. If other reviewers are fine with that, we can fix that up in another PR.
Fixed with d903273cf8e51d2789ba8a88c608a66e63dcdc14.
Concept ACK
Needs rebase again. (Since this has some Concept ACKs, but is somewhat largish, it might be easier to merge in two steps. First the move-only commit in a separate pull request and then the refactoring in this pull request)
67 | + /** 68 | + * m_started_new_line is a state variable that will suppress printing of 69 | + * the timestamp when multiple calls are made that don't end in a 70 | + * newline. 71 | + */ 72 | + std::atomic_bool m_started_new_line{true};
Note that this maintains the old (broken) behaviour:
No need to fix that in this PR.
20 | @@ -19,15 +21,7 @@ static const bool DEFAULT_LOGIPS = false; 21 | static const bool DEFAULT_LOGTIMESTAMPS = true; 22 | extern const char * const DEFAULT_DEBUGLOGFILE; 23 | 24 | -extern bool fPrintToConsole; 25 | -extern bool fPrintToDebugLog; 26 | - 27 | -extern bool fLogTimestamps; 28 | -extern bool fLogTimeMicros; 29 | extern bool fLogIPs;
In commit util: Establish global logger object. : any reason to exclude fLogIPs from g_logger?
It's not actually used by the logger, it's just used in the net code. Arguably it should live there instead.
Tested ACK d903273cf8e51d2789ba8a88c608a66e63dcdc14. Couple of comments inline but nothing to prevent merge.
258 | @@ -264,7 +259,7 @@ void BCLog::Logger::ShrinkDebugFile()
259 | int nBytes = fread(vch.data(), 1, vch.size(), file);
Unrelated nit: Could change int to size_t here, so that it doesn't break when someone changes RECENT_DEBUG_HISTORY_SIZE to 5GB.
132 | - *f = BCLog::ALL; 133 | + if (str == "") { 134 | + flag = BCLog::ALL; 135 | + return true; 136 | + } 137 | + for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
nit: seems like you could phrase this more simply as
for (CLogCategoryDesc& cat : LogCategories) { ... }
There doesn't seem to be a need to have the index on hand.
Nice, fixed. Also gets rid of the dependency of logging on utilstrencodings.
Tested ACK https://github.com/bitcoin/bitcoin/pull/12954/commits/d903273cf8e51d2789ba8a88c608a66e63dcdc14
./src/qt/bitcoin-qt -regtest -conf="$(pwd)/bitcoin.conf" -debug=1./src/qt/bitcoin-qt -testnet -conf="$(pwd)/bitcoin.conf" -debug=0./src/qt/bitcoin-qt -testnet -conf="$(pwd)/bitcoin.conf" -debug=1./src/qt/bitcoin-qt -testnet -conf="$(pwd)/bitcoin.conf" -help-debug../src/bitcoind -debug=foobar./src/bitcoind -debug=1 -debugexclude=net,addrman,rand,leveldb./src/bitcoind -debugexclude=net,addrman,rand,leveldb./src/bitcoind -testnet -config="$(pwd)/bitcoin.conf" -debug=reindex -reindex./src/bitcoind -testnet -config="$(pwd)/bitcoin.conf" -debug=net -reindexNice change. The one nit I had definitely shouldn't hold this up.
The object encapsulates logging configuration, and in a later commit,
set up routines will also be moved into the class.
Changing parameter types from pointers to references and uint32_t to
BCLog::LogFlags simplies calling code.
-BEGIN VERIFY SCRIPT-
sed -i "s/fileout/m_fileout/" src/logging.h src/logging.cpp
sed -i "s/mutexDebugLog/m_file_mutex/" src/logging.h src/logging.cpp
sed -i "s/vMsgsBeforeOpenLog/m_msgs_before_open/" src/logging.h src/logging.cpp
sed -i "s/logCategories/m_categories/" src/logging.h src/logging.cpp
sed -i "s/fPrintToConsole/m_print_to_console/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fPrintToDebugLog/m_print_to_file/" src/logging.h src/logging.cpp src/init.cpp src/test/test_bitcoin.cpp src/bench/bench_bitcoin.cpp
sed -i "s/fLogTimestamps/m_log_timestamps/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fLogTimeMicros/m_log_time_micros/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fReopenDebugLog/m_reopen_file/" src/logging.h src/logging.cpp src/init.cpp
sed -i "s/fStartedNewLine/m_started_new_line/" src/logging.h src/logging.cpp
-END VERIFY SCRIPT-
This breaks the cyclic between logging and util.
utACK 8c2d695c4. Only difference is changing to range based for loops per #12954 (review)
utACK 8c2d695c4a45bdd9378c7970b0fcba6e1efc01f9. Nice to see this encapsulated.