Skip to content

Commit 0b1960f

Browse files
committed
logging: Add DisableLogging()
1 parent 6bbc2dd commit 0b1960f

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <consensus/validation.h>
2222
#include <core_io.h>
23+
#include <logging.h>
2324
#include <node/blockstorage.h>
2425
#include <node/caches.h>
2526
#include <node/chainstate.h>
@@ -42,6 +43,12 @@
4243

4344
int main(int argc, char* argv[])
4445
{
46+
// We do not enable logging for this app, so explicitly disable it.
47+
// To enable logging instead, replace with:
48+
// LogInstance().m_print_to_console = true;
49+
// LogInstance().StartLogging();
50+
LogInstance().DisableLogging();
51+
4552
// SETUP: Argument parsing and handling
4653
if (argc != 2) {
4754
std::cerr

src/logging.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ void BCLog::Logger::DisconnectTestLogger()
9696
m_print_callbacks.clear();
9797
}
9898

99+
void BCLog::Logger::DisableLogging()
100+
{
101+
{
102+
StdLockGuard scoped_lock(m_cs);
103+
assert(m_buffering);
104+
assert(m_print_callbacks.empty());
105+
}
106+
m_print_to_file = false;
107+
m_print_to_console = false;
108+
StartLogging();
109+
}
110+
99111
void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
100112
{
101113
m_categories |= flag;

src/logging.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ namespace BCLog {
157157
/** Only for testing */
158158
void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
159159

160+
/** Disable logging
161+
* This offers a slight speedup and slightly smaller memory usage
162+
* compared to leaving the logging system in its default state.
163+
* Mostly intended for libbitcoin-kernel apps that don't want any logging.
164+
* Should be used instead of StartLogging().
165+
*/
166+
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
167+
160168
void ShrinkDebugFile();
161169

162170
std::unordered_map<LogFlags, Level> CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)

0 commit comments

Comments
 (0)