输出packages:
- phosphor-logging-dev
- phosphor-logging-base
- phosphor-rsyslog-config
phosphor-logging-dev
提供日志API
phosphor-logging支持的error信息需要在phosphor-dbus-interfaces中预定义
phosphor-logging会搜索变量YAML_DIR目录下所有.yaml文件
将.errors.yaml结尾的文件,基于模板生成elog-errors.hpp,elog-lookup.cpp, elog-process-metadata.cpp
phosphor-logging提供两种结构化日志API:log和lg2
phosphor::logging::log
API | header file | Description |
---|---|---|
phosphor::logging::log | log.hpp | Log message to systemd journal |
phosphor::logging::commit | elog.hpp | Create an error log entry based on journal entry with a specified MSG_ID |
phosphor::logging::elog | elog.hpp | Create a journal log entry based on predefined error log information |
phosphor::logging::report | elog.hpp | Create a journal log entry based on predefined error log information and commit the error |
log.h中的API直接将日志发给journald
elog.h中的API会将日志先发送给提供xyz.openbmc_project.Logging.service的进程
phosphor::logging::lg2
lg2.hpp
扩展或优化phosphor::logging::log的功能
需要C++20支持
- The mixture of template and temporary-constructed entry parameters is verbose and clumsy. lg2 is far more succinct in this regard.
- The printf format-strings were error prone and potentially missed in code reviews. lg2 eliminates the need for printf strings by generating the formatting internally.
- logging::log generates incorrect code location information (see openbmc/openbmc#2297). lg2 uses C++20's source_location to, by default, generate correct code location info and can optionally be passed a non-defaulted source_location for rare but appropriate cases.
- The previous APIs had no mechanism to generate dynamic user-friendly strings which caused some developers to rely on external formatting libraries such as {fmt}. {KEY} replacement is now a core feature of the new API.
- When running on a TTY, logging::log sent data to journal and the TTY was silent. This resulted in some applications creating custom code to write some data to stdout and some to logging::log APIs. lg2 automatically detects if it is running on a TTY and duplicates logging data to the console and the journal.
phosphor-log-manager
创建xyz.openbmc_project.Logging.service服务,监听日志请求,发送给journald