MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / InitLogging

Function InitLogging

src/init.cpp:904–961  ·  view source on GitHub ↗

* Initialize global loggers. * * Note that this is called very early in the process lifetime, so you should be * careful about what global state you rely on here. */

Source from the content-addressed store, hash-verified

902 * careful about what global state you rely on here.
903 */
904bool InitLogging()
905{
906 LogInstance().m_print_to_file = SysCfg().GetBoolArg("-logprinttofile", false);
907 LogInstance().m_file_path = AbsPathForConfigVal(SysCfg().GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
908 LogInstance().m_print_to_console = SysCfg().GetBoolArg("-logprinttoconsole", true);
909 LogInstance().m_print_file_line = SysCfg().GetBoolArg("-logprintfileline", false);
910 LogInstance().m_log_timestamps = SysCfg().GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
911 LogInstance().m_log_time_micros = SysCfg().GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
912 LogInstance().m_log_threadnames = SysCfg().GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
913 LogInstance().m_totoal_written_size = LogInstance().GetCurrentLogSize();
914 LogInstance().m_max_log_size = SysCfg().GetArg("-debuglogfilesize", 500 * 1024 * 1024);
915 fLogIPs = SysCfg().GetBoolArg("-logips", DEFAULT_LOGIPS);
916
917 // TODO: ...
918 // nLogMaxSize = GetArg("-logmaxsize", 100) * 1024 * 1024;
919
920 // m_mapMultiArgs["-debug"].push_back("error"); // Enable ERROR logger by default
921
922 // ********************************************************* initialize logging
923 if (SysCfg().IsArgCount("-debug")) {
924 // Special-case: if -debug=0/-nodebug is set, turn off debugging messages
925 const std::vector<std::string> categories = SysCfg().GetMultiArgs("-debug");
926
927 if (std::none_of(categories.begin(), categories.end(),
928 [](std::string cat) { return cat == "0" || cat == "none"; })) {
929 for (const auto& cat : categories) {
930 if (!LogInstance().EnableCategory(cat)) {
931 fprintf(stdout, "Unsupported logging category -debug=%s.\n", cat.c_str());
932 }
933 }
934 }
935 }
936
937
938 if (!LogInstance().StartLogging()) {
939 fprintf(stdout, "Start logging error! log_file=%s",
940 LogInstance().m_file_path.string().c_str());
941 return false;
942 }
943
944 std::string version_string = FormatFullVersion();
945#ifdef VER_DEBUG
946 version_string += " (debug build)";
947#else
948 version_string += " (release build)";
949#endif
950 LogPrint(BCLog::INFO, PACKAGE_NAME " version %s\n", version_string);
951
952 // LogInstance().DisableCategory("INFO");
953 // LogInstance().EnableCategory("NET");
954 // if (GetBoolArg("-shrinkdebugfile", !fDebug))
955 // ShrinkDebugFile();
956
957 if (!LogInstance().m_log_timestamps)
958 LogPrint(BCLog::INFO, "Startup time: %s\n", FormatISO8601DateTime(GetTime()));
959
960 return true;
961}

Callers 1

AppInitFunction · 0.85

Calls 12

AbsPathForConfigValFunction · 0.85
FormatFullVersionFunction · 0.85
FormatISO8601DateTimeFunction · 0.85
GetTimeFunction · 0.85
GetBoolArgMethod · 0.80
GetArgMethod · 0.80
GetCurrentLogSizeMethod · 0.80
IsArgCountMethod · 0.80
EnableCategoryMethod · 0.80
StartLoggingMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected