diff options
author | Anthony Towns <aj@erisian.com.au> | 2024-07-04 00:52:29 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2024-07-12 10:30:39 +1000 |
commit | 0b1960f1b29cfe5209ac68102c8643fc9553f247 (patch) | |
tree | c26c6c716b5933a0b41b43aa634edfaead37ef52 | |
parent | 6bbc2dd6c50f09ff1e70423dc29a404b570f5b69 (diff) | |
download | bitcoin-0b1960f1b29cfe5209ac68102c8643fc9553f247.tar.xz |
logging: Add DisableLogging()
-rw-r--r-- | src/bitcoin-chainstate.cpp | 7 | ||||
-rw-r--r-- | src/logging.cpp | 12 | ||||
-rw-r--r-- | src/logging.h | 8 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index ecbdcd48bb..697096586e 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -20,6 +20,7 @@ #include <consensus/validation.h> #include <core_io.h> +#include <logging.h> #include <node/blockstorage.h> #include <node/caches.h> #include <node/chainstate.h> @@ -42,6 +43,12 @@ int main(int argc, char* argv[]) { + // We do not enable logging for this app, so explicitly disable it. + // To enable logging instead, replace with: + // LogInstance().m_print_to_console = true; + // LogInstance().StartLogging(); + LogInstance().DisableLogging(); + // SETUP: Argument parsing and handling if (argc != 2) { std::cerr diff --git a/src/logging.cpp b/src/logging.cpp index a9fea433be..53af7d5ca7 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -96,6 +96,18 @@ void BCLog::Logger::DisconnectTestLogger() m_print_callbacks.clear(); } +void BCLog::Logger::DisableLogging() +{ + { + StdLockGuard scoped_lock(m_cs); + assert(m_buffering); + assert(m_print_callbacks.empty()); + } + m_print_to_file = false; + m_print_to_console = false; + StartLogging(); +} + void BCLog::Logger::EnableCategory(BCLog::LogFlags flag) { m_categories |= flag; diff --git a/src/logging.h b/src/logging.h index 2f24f32886..70539f03b0 100644 --- a/src/logging.h +++ b/src/logging.h @@ -157,6 +157,14 @@ namespace BCLog { /** Only for testing */ void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs); + /** Disable logging + * This offers a slight speedup and slightly smaller memory usage + * compared to leaving the logging system in its default state. + * Mostly intended for libbitcoin-kernel apps that don't want any logging. + * Should be used instead of StartLogging(). + */ + void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs); + void ShrinkDebugFile(); std::unordered_map<LogFlags, Level> CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs) |