Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | |||||
* so we restrict handler operations to just touching variables: | * so we restrict handler operations to just touching variables: | ||||
*/ | */ | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
static void HandleSIGTERM(int) { | static void HandleSIGTERM(int) { | ||||
StartShutdown(); | StartShutdown(); | ||||
} | } | ||||
static void HandleSIGHUP(int) { | static void HandleSIGHUP(int) { | ||||
GetLogger().m_reopen_file = true; | LogInstance().m_reopen_file = true; | ||||
} | } | ||||
#else | #else | ||||
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType) { | static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType) { | ||||
StartShutdown(); | StartShutdown(); | ||||
Sleep(INFINITE); | Sleep(INFINITE); | ||||
return true; | return true; | ||||
} | } | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 1,048 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Initialize global loggers. | * Initialize global loggers. | ||||
* | * | ||||
* Note that this is called very early in the process lifetime, so you should be | * Note that this is called very early in the process lifetime, so you should be | ||||
* careful about what global state you rely on here. | * careful about what global state you rely on here. | ||||
*/ | */ | ||||
void InitLogging() { | void InitLogging() { | ||||
BCLog::Logger &logger = GetLogger(); | LogInstance().m_print_to_file = !gArgs.IsArgNegated("-debuglogfile"); | ||||
logger.m_print_to_file = !gArgs.IsArgNegated("-debuglogfile"); | LogInstance().m_file_path = AbsPathForConfigVal( | ||||
logger.m_file_path = AbsPathForConfigVal( | |||||
gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE)); | gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE)); | ||||
// Add newlines to the logfile to distinguish this execution from the last | // Add newlines to the logfile to distinguish this execution from the last | ||||
// one; called before console logging is set up, so this is only sent to | // one; called before console logging is set up, so this is only sent to | ||||
// debug.log. | // debug.log. | ||||
LogPrintf("\n\n\n\n\n"); | LogPrintf("\n\n\n\n\n"); | ||||
logger.m_print_to_console = gArgs.GetBoolArg( | LogInstance().m_print_to_console = gArgs.GetBoolArg( | ||||
"-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); | "-printtoconsole", !gArgs.GetBoolArg("-daemon", false)); | ||||
logger.m_log_timestamps = | LogInstance().m_log_timestamps = | ||||
gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | gArgs.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS); | ||||
logger.m_log_time_micros = | LogInstance().m_log_time_micros = | ||||
gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | gArgs.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS); | ||||
fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); | fLogIPs = gArgs.GetBoolArg("-logips", DEFAULT_LOGIPS); | ||||
LogPrintf("%s version %s\n", CLIENT_NAME, FormatFullVersion()); | LogPrintf("%s version %s\n", CLIENT_NAME, FormatFullVersion()); | ||||
} | } | ||||
namespace { // Variables internal to initialization process only | namespace { // Variables internal to initialization process only | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | bool AppInitParameterInteraction(Config &config) { | ||||
if (gArgs.IsArgSet("-debug")) { | if (gArgs.IsArgSet("-debug")) { | ||||
// Special-case: if -debug=0/-nodebug is set, turn off debugging | // Special-case: if -debug=0/-nodebug is set, turn off debugging | ||||
// messages | // messages | ||||
const std::vector<std::string> &categories = gArgs.GetArgs("-debug"); | const std::vector<std::string> &categories = gArgs.GetArgs("-debug"); | ||||
if (std::none_of( | if (std::none_of( | ||||
categories.begin(), categories.end(), | categories.begin(), categories.end(), | ||||
[](std::string cat) { return cat == "0" || cat == "none"; })) { | [](std::string cat) { return cat == "0" || cat == "none"; })) { | ||||
for (const auto &cat : categories) { | for (const auto &cat : categories) { | ||||
if (!GetLogger().EnableCategory(cat)) { | if (!LogInstance().EnableCategory(cat)) { | ||||
InitWarning( | InitWarning( | ||||
strprintf(_("Unsupported logging category %s=%s."), | strprintf(_("Unsupported logging category %s=%s."), | ||||
"-debug", cat)); | "-debug", cat)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Now remove the logging categories which were explicitly excluded | // Now remove the logging categories which were explicitly excluded | ||||
for (const std::string &cat : gArgs.GetArgs("-debugexclude")) { | for (const std::string &cat : gArgs.GetArgs("-debugexclude")) { | ||||
if (!GetLogger().DisableCategory(cat)) { | if (!LogInstance().DisableCategory(cat)) { | ||||
InitWarning(strprintf(_("Unsupported logging category %s=%s."), | InitWarning(strprintf(_("Unsupported logging category %s=%s."), | ||||
"-debugexclude", cat)); | "-debugexclude", cat)); | ||||
} | } | ||||
} | } | ||||
// Check for -debugnet | // Check for -debugnet | ||||
if (gArgs.GetBoolArg("-debugnet", false)) { | if (gArgs.GetBoolArg("-debugnet", false)) { | ||||
InitWarning( | InitWarning( | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | bool AppInitMain(Config &config, RPCServer &rpcServer, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | ||||
// Step 4a: application initialization | // Step 4a: application initialization | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
CreatePidFile(GetPidFile(), getpid()); | CreatePidFile(GetPidFile(), getpid()); | ||||
#endif | #endif | ||||
BCLog::Logger &logger = GetLogger(); | BCLog::Logger &logger = LogInstance(); | ||||
if (logger.m_print_to_file) { | if (logger.m_print_to_file) { | ||||
if (gArgs.GetBoolArg("-shrinkdebugfile", | if (gArgs.GetBoolArg("-shrinkdebugfile", | ||||
logger.DefaultShrinkDebugFile())) { | logger.DefaultShrinkDebugFile())) { | ||||
// Do this first since it both loads a bunch of debug.log into | // Do this first since it both loads a bunch of debug.log into | ||||
// memory, and because this needs to happen before any other | // memory, and because this needs to happen before any other | ||||
// debug.log printing. | // debug.log printing. | ||||
logger.ShrinkDebugFile(); | logger.ShrinkDebugFile(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 655 Lines • Show Last 20 Lines |