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返回的单例对象中

相关推荐
多弗朗皮卡丘1 小时前
Linux 进程信号
linux·运维·服务器
^乘风破浪^1 小时前
Kali配置i3wm教程1
linux·kali·i3wm
qeen871 小时前
【Linux】动静态库的链接与加载过程
linux·运维·系统编程
重生之小比特2 小时前
【Linux系统】17 库制作与原理(上)
linux·运维·服务器
wzg20162 小时前
ubuntu 离线安装 docker-compose
linux·ubuntu·docker
行走的陀螺仪3 小时前
Claude Code 从入门到实战(三):Hooks、Skills、SubAgents 高级扩展
linux·编辑器·vim
Brilliantwxx3 小时前
【STM32】 内部 Flash 的 HAL 库函数详解与自定义封装实战
linux·服务器·网络
码途行者4 小时前
Linux 服务器 Golang 安装及环境变量配置
linux·运维·服务器
叼烟扛炮4 小时前
Linux 学习笔记(四十七):TCP 状态机与 tcpdump 抓包排雷实战
linux·网络·笔记·学习·tcp/ip·tcpdump
爱和冰阔落4 小时前
【Linux网络】UDP 聊天室怎么实现?从在线用户管理、消息广播到双线程收发与线程池
linux·运维·网络·udp