* 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. */
| 902 | * careful about what global state you rely on here. |
| 903 | */ |
| 904 | bool 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 | } |
no test coverage detected