std::unordered_map parseLogFeatures()

in prod/native/libcommon/code/CommonUtils.cpp [268:293]


std::unordered_map<elasticapm::php::LogFeature, LogLevel> parseLogFeatures(std::shared_ptr<elasticapm::php::LoggerInterface> logger, std::string_view logFeatures) {
    std::unordered_map<elasticapm::php::LogFeature, LogLevel> features;

    if (!logFeatures.empty()) {
        using namespace std::string_view_literals;
        for (const auto split : std::views::split(logFeatures, ","sv)) {
            std::string_view featureAndValue(split);
            auto pos = featureAndValue.find('=');
            if (pos != std::string_view::npos) {
                std::string_view option = featureAndValue.substr(0, pos);
                std::string_view value = featureAndValue.substr(pos + 1);

                try {
                    auto level = parseLogLevel(value);
                    auto feature = elasticapm::php::parseLogFeature(option);
                    features.emplace(feature, level);
                } catch (std::invalid_argument const &e) {
                    ELOGF_NF_WARNING(logger, "Error while parsing LogFeature " PRsv ", exception: %s ", PRsvArg(featureAndValue), e.what());
                }
            } else {
                ELOGF_NF_WARNING(logger, "Error while parsing LogFeature " PRsv, PRsvArg(featureAndValue));
            }
        }
    }
    return features;
}