OpenBMC:BmcWeb定义service

1.定义service

cpp 复制代码
//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.设置日志级别

cpp 复制代码
//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;
}
cpp 复制代码
//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返回的单例对象中

相关推荐
java叶新东老师2 小时前
git stash 命令详解
linux·运维·flink
写bug的羊羊3 小时前
CentOS 9 配置国内 YUM 源
linux·运维·centos
Johny_Zhao6 小时前
CentOS Stream 9上部署FTP应用服务的两种方法(传统安装和docker-compose)
linux·网络安全·信息安全·kubernetes·云计算·containerd·ftp·yum源·系统运维
守望时空336 小时前
RustDesk搭建指南
linux
C++ 老炮儿的技术栈6 小时前
在 Scintilla 中为 Squirrel 语言设置语法解析器的方法
linux·运维·c++·git·ubuntu·github·visual studio
白鹭7 小时前
基于LNMP架构的分布式个人博客搭建
linux·运维·服务器·网络·分布式·apache
java叶新东老师7 小时前
linux 部署 flink 1.15.1 并提交作业
linux·运维·flink
程序员JerrySUN8 小时前
Linux系统架构核心全景详解
linux·运维·系统架构
无敌的牛8 小时前
Linux文件理解,基础IO理解
linux·运维·服务器
未来之窗软件服务8 小时前
跨平台 WebSocket 服务器的设计与实现 —— 基于.NET 8 的跨操作系统解决方案linux,macos,windows——开发工具
linux·服务器·websocket·仙盟创梦ide·东方仙盟