当前位置: 首页 > news >正文

OpenBMC:BmcWeb定义service

1.定义service

//src\webserver_run.cpp

int run()
{
    ...
    std::shared_ptr<sdbusplus::asio::connection> systemBus =
        std::make_shared<sdbusplus::asio::connection>(io);
    crow::connections::systemBus = systemBus.get();

    auto server = sdbusplus::asio::object_server(systemBus);

    std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
        server.add_interface("/xyz/openbmc_project/bmcweb",
                             "xyz.openbmc_project.bmcweb");

    iface->register_method("SetLogLevel", setLogLevel);

    iface->initialize();
    ...

    systemBus->request_name("xyz.openbmc_project.bmcweb");
    ...
}

为BmcWeb定义了

Service:xyz.openbmc_project.bmcweb

ObjPath:/xyz/openbmc_project/bmcweb

Interface:xyz.openbmc_project.bmcweb

Method:SetLogLevel

 2.设置日志级别

//http\logging.hpp
constexpr std::array<std::string_view, 7> mapLogLevelFromName{
    "DISABLED", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "ENABLED"};

constexpr crow::LogLevel getLogLevelFromName(std::string_view name)
{
    const auto* iter = std::ranges::find(mapLogLevelFromName, name);
    if (iter != mapLogLevelFromName.end())
    {
        return static_cast<LogLevel>(iter - mapLogLevelFromName.begin());
    }
    return crow::LogLevel::Disabled;
}

enum class LogLevel
{
    Disabled = 0,
    Critical,
    Error,
    Warning,
    Info,
    Debug,
    Enabled,
};

inline crow::LogLevel& getBmcwebCurrentLoggingLevel()
{
    static crow::LogLevel level = getLogLevelFromName(BMCWEB_LOGGING_LEVEL);
    return level;
}
//src\webserver_run.cpp
static void setLogLevel(const std::string& logLevel)
{
    const std::basic_string_view<char>* iter =
        std::ranges::find(crow::mapLogLevelFromName, logLevel);
    if (iter == crow::mapLogLevelFromName.end())
    {
        BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
        return;
    }
    crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
    BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
}

BmcWeb被实现为一个service,目的只有一个就是设置日志级别

而日志级别被保存在函数getBmcwebCurrentLoggingLevel返回的单例对象中

相关文章:

  • R包的作用及安装指南
  • Oracle和Mysql的区别
  • 14.8 Auto-GPT 自主智能体设计解密:构建具备长期记忆的智能决策系统
  • 微软Win11新动态:官方“换机助手”曝光,PC数据迁移或迎全新体验
  • 知识库管理系统驱动企业知识体系重构与智能协作路径解析
  • 前端工程化
  • 【Web前端开发精品课 HTML CSS JavaScript基础教程】第二十六章课后题答案
  • (面试经典问题之内存池篇)内存池构成、作用及其基本原理详解
  • 【程序人生】软件架构师职业发展规划 (2023)
  • 使用Java实现高可用性分布式系统
  • 人工智能之视频分割模型sam2源码解读
  • 尝试在exo集群下使用deepseek模型:第一步,调通llama
  • Paimon(数据湖框架)概述
  • 想象一个AI保姆机器人使用场景分析
  • 故障诊断 | DCS差异创意搜索算法优化CatBoost故障诊断(MatlabPython)
  • 数组与对象的元素添加
  • Unity游戏制作中的C#基础(2)变量与数据类型
  • c/c++蓝桥杯经典编程题100道(22)最短路径问题
  • 什么是CoT(带有长链思维)的Few-shot Prompting(少样本提示)
  • 【HarmonyOS Next】拒绝权限二次申请授权处理
  • 金昌网站建设/独立站seo
  • 微信网站下载/收录优美的图片
  • 兰山网站建设/今天刚刚发生的新闻最新新闻
  • 电子商务网站建设(论文/网站搜索引擎优化的基本内容
  • 服务公司取名/郑州seo使用教程
  • 直播类网站开发/百度网站排名查询工具