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.
150- } \
151-} while(0)
152-#endif
153-
154 template<typename... Args>
155 bool error(const char* fmt, const Args&... args)
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.
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;
fLogIPs
from g_logger
?
258@@ -264,7 +259,7 @@ void BCLog::Logger::ShrinkDebugFile()
259 int nBytes = fread(vch.data(), 1, vch.size(), file);
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
0for (CLogCategoryDesc& cat : LogCategories) { ... }
There doesn’t seem to be a need to have the index on hand.
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 -reindex
Nice 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.