Repository: bitcoin/bitcoin
File: src/init/common.cpp (C++)

Code before:

    // Now remove the logging categories which were explicitly excluded
    for (const std::string& cat : args.GetArgs("-debugexclude")) {
        if (!LogInstance().DisableCategory(cat)) {
            return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat)};
        }
    }
    return {};
}

bool StartLogging(const ArgsManager& args)
{
    if (LogInstance().m_print_to_file) {
        if (args.GetBoolArg("-shrinkdebugfile", LogInstance().DefaultShrinkDebugFile())) {
            // Do this first since it both loads a bunch of debug.log into memory,
            // and because this needs to happen before any other debug.log printing
            LogInstance().ShrinkDebugFile();
        }
    }
    if (!LogInstance().StartLogging()) {
            return InitError(Untranslated(strprintf("Could not open debug log file %s",
                fs::PathToString(LogInstance().m_file_path))));
    }

    if (!LogInstance().m_log_timestamps)
        LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
    LogPrintf("Default data directory %s\n", fs::PathToString(GetDefaultDataDir()));
    LogPrintf("Using data directory %s\n", fs::PathToString(gArgs.GetDataDirNet()));

    // Only log conf file usage message if conf file actually exists.
    fs::path config_file_path = args.GetConfigFilePath();
    if (args.IsArgNegated("-conf")) {
        LogInfo("Config file: <disabled>");
    } else if (fs::is_directory(config_file_path)) {
        LogWarning("Config file: %s (is directory, not file)", fs::PathToString(config_file_path));
    } else if (fs::exists(config_file_path)) {
        LogPrintf("Config file: %s\n", fs::PathToString(config_file_path));
    } else if (args.IsArgSet("-conf")) {
        InitWarning(strprintf(_("The specified config file %s does not exist"), fs::PathToString(config_file_path)));
    } else {
        // Not categorizing as "Warning" because it's the default behavior
        LogPrintf("Config file: %s (not found, skipping)\n", fs::PathToString(config_file_path));
    }

    // Log the config arguments to debug.log
    args.LogArgs();

    return true;
}

void LogPackageVersion()

Review comment (suggestion):
nit, if you touch again, please consider adding braces here to avoid any confusion caused by other surrounding logs

Code after:

    // Now remove the logging categories which were explicitly excluded
    for (const std::string& cat : args.GetArgs("-debugexclude")) {
        if (!LogInstance().DisableCategory(cat)) {
            return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat)};
        }
    }
    return {};
}

bool StartLogging(const ArgsManager& args)
{
    if (LogInstance().m_print_to_file) {
        if (args.GetBoolArg("-shrinkdebugfile", LogInstance().DefaultShrinkDebugFile())) {
            // Do this first since it both loads a bunch of debug.log into memory,
            // and because this needs to happen before any other debug.log printing
            LogInstance().ShrinkDebugFile();
        }
    }
    if (!LogInstance().StartLogging()) {
            return InitError(Untranslated(strprintf("Could not open debug log file %s",
                fs::PathToString(LogInstance().m_file_path))));
    }

    if (!LogInstance().m_log_timestamps) {
        LogInfo("Startup time: %s", FormatISO8601DateTime(GetTime()));
    }
    LogInfo("Default data directory %s", fs::PathToString(GetDefaultDataDir()));
    LogInfo("Using data directory %s", fs::PathToString(gArgs.GetDataDirNet()));

    // Only log conf file usage message if conf file actually exists.
    fs::path config_file_path = args.GetConfigFilePath();
    if (args.IsArgNegated("-conf")) {
        LogInfo("Config file: <disabled>");
    } else if (fs::is_directory(config_file_path)) {
        LogWarning("Config file: %s (is directory, not file)", fs::PathToString(config_file_path));
    } else if (fs::exists(config_file_path)) {
        LogInfo("Config file: %s", fs::PathToString(config_file_path));
    } else if (args.IsArgSet("-conf")) {
        InitWarning(strprintf(_("The specified config file %s does not exist"), fs::PathToString(config_file_path)));
    } else {
        // Not categorizing as "Warning" because it's the default behavior
        LogInfo("Config file: %s (not found, skipping)", fs::PathToString(config_file_path));
    }

    // Log the config arguments to debug.log
    args.LogArgs();

    return true;
}