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

相关推荐
hello_ world.16 分钟前
RHCA10NUMA
linux
神秘人X7071 小时前
Linux高效备份:rsync + inotify实时同步
linux·服务器·rsync
轻松Ai享生活1 小时前
一步步学习Linux initrd/initramfs
linux
轻松Ai享生活1 小时前
一步步深入学习Linux Process Scheduling
linux
绵绵细雨中的乡音3 小时前
网络基础知识
linux·网络
Peter·Pan爱编程3 小时前
Docker在Linux中安装与使用教程
linux·docker·eureka
kunge20134 小时前
Ubuntu22.04 安装virtualbox7.1
linux·virtualbox
清溪5494 小时前
DVWA中级
linux
Sadsvit5 小时前
源码编译安装LAMP架构并部署WordPress(CentOS 7)
linux·运维·服务器·架构·centos
xiaok5 小时前
为什么 lsof 显示多个 nginx 都在 “使用 443”?
linux