diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index ecbdcd48bb3..697096586e5 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -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 a9fea433be4..53af7d5ca72 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 2f24f328861..70539f03b05 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 CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)