Changeset View
Changeset View
Standalone View
Standalone View
src/logging.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2018 The Bitcoin developers | // Copyright (c) 2017-2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
bool fLogIPs = DEFAULT_LOGIPS; | bool fLogIPs = DEFAULT_LOGIPS; | ||||
const char *const DEFAULT_DEBUGLOGFILE = "debug.log"; | const char *const DEFAULT_DEBUGLOGFILE = "debug.log"; | ||||
BCLog::Logger &LogInstance() { | |||||
/** | /** | ||||
* NOTE: the logger instance is leaked on exit. This is ugly, but will be | * NOTE: the logger instance is leaked on exit. This is ugly, but will be | ||||
* cleaned up by the OS/libc. Defining a logger as a global object doesn't work | * cleaned up by the OS/libc. Defining a logger as a global object doesn't | ||||
* since the order of destruction of static/global objects is undefined. | * work since the order of destruction of static/global objects is | ||||
* Consider if the logger gets destroyed, and then some later destructor calls | * undefined. Consider if the logger gets destroyed, and then some later | ||||
* LogPrintf, maybe indirectly, and you get a core dump at shutdown trying to | * destructor calls LogPrintf, maybe indirectly, and you get a core dump at | ||||
* access the logger. When the shutdown sequence is fully audited and tested, | * shutdown trying to access the logger. When the shutdown sequence is fully | ||||
* explicit destruction of these objects can be implemented by changing this | * audited and tested, explicit destruction of these objects can be | ||||
* from a raw pointer to a std::unique_ptr. | * implemented by changing this from a raw pointer to a std::unique_ptr. | ||||
* Since the destructor is never called, the logger and all its members must | |||||
* have a trivial destructor. | |||||
* | * | ||||
* This method of initialization was originally introduced in | * This method of initialization was originally introduced in | ||||
* ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c. | * ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c. | ||||
*/ | */ | ||||
BCLog::Logger &GetLogger() { | static BCLog::Logger *g_logger{new BCLog::Logger()}; | ||||
static BCLog::Logger *const logger = new BCLog::Logger(); | return *g_logger; | ||||
return *logger; | |||||
} | } | ||||
static int FileWriteStr(const std::string &str, FILE *fp) { | static int FileWriteStr(const std::string &str, FILE *fp) { | ||||
return fwrite(str.data(), 1, str.size(), fp); | return fwrite(str.data(), 1, str.size(), fp); | ||||
} | } | ||||
bool BCLog::Logger::OpenDebugLog() { | bool BCLog::Logger::OpenDebugLog() { | ||||
std::lock_guard<std::mutex> scoped_lock(m_file_mutex); | std::lock_guard<std::mutex> scoped_lock(m_file_mutex); | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |