xref: /openbmc/phosphor-logging/README.md (revision d1fc909a9d7b2c5047a8566ebfa76568d2c1c913)
17aafb12eSNagaraju Goruganti# phosphor-logging
226919f07SPatrick Williams
3c41693c6SMatt SpinlerThe phosphor logging repository provides mechanisms for event and journal
4c41693c6SMatt Spinlerlogging.
5c41693c6SMatt Spinler
6c41693c6SMatt Spinler## Table Of Contents
726919f07SPatrick Williams
826919f07SPatrick Williams- [Building](#to-build)
926919f07SPatrick Williams- [Structured Logging](#structured-logging)
1026919f07SPatrick Williams- [Event Logs](#event-logs)
1126919f07SPatrick Williams- [Application Specific Error YAML](#adding-application-specific-error-yaml)
1226919f07SPatrick Williams- [Event Log Extensions](#event-log-extensions)
1326919f07SPatrick Williams- [Remote Logging](#remote-logging-via-rsyslog)
1426919f07SPatrick Williams- [Boot Fail on Hardware Errors](#boot-fail-on-hardware-errors)
157aafb12eSNagaraju Goruganti
167aafb12eSNagaraju Goruganti## To Build
1726919f07SPatrick Williams
187aafb12eSNagaraju GorugantiTo build this package, do the following steps:
197aafb12eSNagaraju Goruganti
207bc39084SPatrick Williams1. meson builddir
217bc39084SPatrick Williams2. ninja -c builddir
229067c077SDeepak Kodihalli
2387896d58SPatrick Williams## Structured Logging
2487896d58SPatrick Williams
2526919f07SPatrick Williamsphosphor-logging provides APIs to add program logging information to the
2626919f07SPatrick Williamssystemd-journal and it is preferred that this logging data is formatted in a
2726919f07SPatrick Williamsstructured manner (using the facilities provided by the APIs).
2826919f07SPatrick Williams
2926919f07SPatrick WilliamsSee [Structured Logging](./docs/structured-logging.md) for more details on this
3026919f07SPatrick WilliamsAPI.
3187896d58SPatrick Williams
320a2c1a23SMatt Spinler## Event Logs
3326919f07SPatrick Williams
340a2c1a23SMatt SpinlerOpenBMC event logs are a collection of D-Bus interfaces owned by
350a2c1a23SMatt Spinlerphosphor-log-manager that reside at `/xyz/openbmc_project/logging/entry/X`,
360a2c1a23SMatt Spinlerwhere X starts at 1 and is incremented for each new log.
370a2c1a23SMatt Spinler
380a2c1a23SMatt SpinlerThe interfaces are:
390a2c1a23SMatt Spinler
4026919f07SPatrick Williams- [xyz.openbmc_project.Logging.Entry]
4126919f07SPatrick Williams  - The main event log interface.
4226919f07SPatrick Williams- [xyz.openbmc_project.Association.Definitions]
4326919f07SPatrick Williams  - Used for specifying inventory items as the cause of the event.
4426919f07SPatrick Williams  - For more information on associations, see [here][associations-doc].
4526919f07SPatrick Williams- [xyz.openbmc_project.Object.Delete]
4626919f07SPatrick Williams  - Provides a Delete method to delete the event.
4726919f07SPatrick Williams- [xyz.openbmc_project.Software.Version]
4826919f07SPatrick Williams  - Stores the code version that the error occurred on.
4926919f07SPatrick Williams
5026919f07SPatrick WilliamsOn platforms that make use of these event logs, the intent is that they are the
5126919f07SPatrick Williamscommon event log representation that other types of event logs can be created
5226919f07SPatrick Williamsfrom. For example, there is code to convert these into both Redfish and IPMI
5326919f07SPatrick Williamsevent logs, in addition to the event log extensions mentioned
540a2c1a23SMatt Spinler[below](#event-log-extensions).
550a2c1a23SMatt Spinler
5626919f07SPatrick WilliamsThe logging daemon has the ability to add `callout` associations to an event log
5726919f07SPatrick Williamsbased on text in the AdditionalData property. A callout is a link to the
580a2c1a23SMatt Spinlerinventory item(s) that were the cause of the event log. See [here][callout-doc]
590a2c1a23SMatt Spinlerfor details.
600a2c1a23SMatt Spinler
610a2c1a23SMatt Spinler### Creating Event Logs In Code
6226919f07SPatrick Williams
635effae2dSPatrick WilliamsThe preferred method for creating event logs is specified in the project-level
645effae2dSPatrick Williams[event log design][event-log-design]. Events are defined using YAML in the
655effae2dSPatrick Williamsphosphor-dbus-interfaces repository, such as the
665effae2dSPatrick Williams[Logging.Cleared][logging-cleared] event, which will generate a C++ class for
675effae2dSPatrick Williamsthe event. Then a call to `lg2::commit` is made on a constructed event to add it
685effae2dSPatrick Williamsto the event log.
690a2c1a23SMatt Spinler
705effae2dSPatrick Williams```cpp
715effae2dSPatrick Williamslg2::commit(sdbusplus::event::xyz::openbmc_project::Logging::Cleared(
725effae2dSPatrick Williams    "NUMBER_OF_LOGS", count));
735effae2dSPatrick Williams```
745effae2dSPatrick Williams
755effae2dSPatrick WilliamsThere are two other, but now deprecated, methods to creating event logs in
765effae2dSPatrick WilliamsOpenBMC code. The first makes use of the systemd journal to store metadata
775effae2dSPatrick Williamsneeded for the log, and the second is a plain D-Bus method call.
785effae2dSPatrick Williams
795effae2dSPatrick Williams[event-log-design]:
805effae2dSPatrick Williams  https://github.com/openbmc/docs/blob/master/designs/event-logging.md#phosphor-logging
815effae2dSPatrick Williams[logging-cleared]:
825effae2dSPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/6a8507d06e172d8d29c0459f0a0d078553d2ecc7/yaml/xyz/openbmc_project/Logging.events.yaml#L4
835effae2dSPatrick Williams
845effae2dSPatrick Williams#### Journal Based Event Log Creation [deprecated]
8526919f07SPatrick Williams
860a2c1a23SMatt SpinlerEvent logs can be created by using phosphor-logging APIs to commit sdbusplus
8726919f07SPatrick Williamsexceptions. These APIs write to the journal, and then call a `Commit` D-Bus
8826919f07SPatrick Williamsmethod on the logging daemon to create the event log using the information it
8926919f07SPatrick Williamsput in the journal.
900a2c1a23SMatt Spinler
910a2c1a23SMatt SpinlerThe APIs are found in `<phosphor-logging/elog.hpp>`:
9226919f07SPatrick Williams
9326919f07SPatrick Williams- `elog()`: Throw an sdbusplus error.
9426919f07SPatrick Williams- `commit()`: Catch an error thrown by elog(), and commit it to create the event
9526919f07SPatrick Williams  log.
9626919f07SPatrick Williams- `report()`: Create an event log from an sdbusplus error without throwing the
970a2c1a23SMatt Spinler  exception first.
980a2c1a23SMatt Spinler
9926919f07SPatrick WilliamsAny errors passed into these APIs must be known to phosphor-logging, usually by
10026919f07SPatrick Williamsbeing defined in `<phosphor-logging/elog-errors.hpp>`. The errors must also be
10126919f07SPatrick Williamsknown by sdbusplus, and be defined in their corresponding error.hpp. See below
10226919f07SPatrick Williamsfor details on how get errors into these headers.
1030a2c1a23SMatt Spinler
1040a2c1a23SMatt SpinlerExample:
10526919f07SPatrick Williams
106140d496eSJagpal Singh Gill```cpp
1070a2c1a23SMatt Spinler#include <phosphor-logging/elog-errors.hpp>
1080a2c1a23SMatt Spinler#include <phosphor-logging/elog.hpp>
1090a2c1a23SMatt Spinler#include <xyz/openbmc_project/Common/error.hpp>
1100a2c1a23SMatt Spinler...
1110a2c1a23SMatt Spinlerusing InternalFailure =
1120a2c1a23SMatt Spinler    sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
1130a2c1a23SMatt Spinler...
1140a2c1a23SMatt Spinlerif (somethingBadHappened)
1150a2c1a23SMatt Spinler{
1160a2c1a23SMatt Spinler    phosphor::logging::report<InternalFailure>();
1170a2c1a23SMatt Spinler}
1180a2c1a23SMatt Spinler
1190a2c1a23SMatt Spinler```
12026919f07SPatrick Williams
1210a2c1a23SMatt SpinlerAlternatively, to throw, catch, and then commit the error:
12226919f07SPatrick Williams
123140d496eSJagpal Singh Gill```cpp
1240a2c1a23SMatt Spinlertry
1250a2c1a23SMatt Spinler{
1260a2c1a23SMatt Spinler    phosphor::logging::elog<InternalFailure>();
1270a2c1a23SMatt Spinler}
1280a2c1a23SMatt Spinlercatch (InternalFailure& e)
1290a2c1a23SMatt Spinler{
1300a2c1a23SMatt Spinler    phosphor::logging::commit<InternalFailure>();
1310a2c1a23SMatt Spinler}
1320a2c1a23SMatt Spinler```
1330a2c1a23SMatt Spinler
1340a2c1a23SMatt SpinlerMetadata can be added to event logs to add debug data captured at the time of
1350a2c1a23SMatt Spinlerthe event. It shows up in the AdditionalData property in the
1360a2c1a23SMatt Spinler`xyz.openbmc_project.Logging.Entry` interface. Metadata is passed in via the
1370a2c1a23SMatt Spinler`elog()` or `report()` functions, which write it to the journal. The metadata
1380a2c1a23SMatt Spinlermust be predefined for the error in the [metadata YAML](#event-log-definition)
13926919f07SPatrick Williamsso that the daemon knows to look for it in the journal when it creates the event
14026919f07SPatrick Williamslog.
1410a2c1a23SMatt Spinler
1420a2c1a23SMatt SpinlerExample:
14326919f07SPatrick Williams
144140d496eSJagpal Singh Gill```cpp
1450a2c1a23SMatt Spinler#include <phosphor-logging/elog-errors.hpp>
1460a2c1a23SMatt Spinler#include <phosphor-logging/elog.hpp>
1470a2c1a23SMatt Spinler#include <xyz/openbmc_project/Control/Device/error.hpp>
1480a2c1a23SMatt Spinler...
1490a2c1a23SMatt Spinlerusing WriteFailure =
1500a2c1a23SMatt Spinler    sdbusplus::xyz::openbmc_project::Control::Device::Error::WriteFailure;
1510a2c1a23SMatt Spinlerusing metadata =
152*d1fc909aSDaniel Hsu    phosphor::logging::xyz::openbmc_project::Control::Device::WriteFailure;
1530a2c1a23SMatt Spinler...
1540a2c1a23SMatt Spinlerif (somethingBadHappened)
1550a2c1a23SMatt Spinler{
1560a2c1a23SMatt Spinler    phosphor::logging::report<WriteFailure>(metadata::CALLOUT_ERRNO(5),
1570a2c1a23SMatt Spinler                              metadata::CALLOUT_DEVICE_PATH("some path"));
1580a2c1a23SMatt Spinler}
1590a2c1a23SMatt Spinler```
16026919f07SPatrick Williams
1610a2c1a23SMatt SpinlerIn the above example, the AdditionalData property would look like:
16226919f07SPatrick Williams
163140d496eSJagpal Singh Gill```cpp
1640a2c1a23SMatt Spinler["CALLOUT_ERRNO=5", "CALLOUT_DEVICE_PATH=some path"]
1650a2c1a23SMatt Spinler```
16626919f07SPatrick Williams
1670a2c1a23SMatt SpinlerNote that the metadata fields must be all uppercase.
1680a2c1a23SMatt Spinler
1695effae2dSPatrick Williams##### Event Log Definition [deprecated]
17026919f07SPatrick Williams
1710a2c1a23SMatt SpinlerAs mentioned above, both sdbusplus and phosphor-logging must know about the
1720a2c1a23SMatt Spinlerevent logs in their header files, or the code that uses them will not even
1730a2c1a23SMatt Spinlercompile. The standard way to do this to define the event in the appropriate
1740a2c1a23SMatt Spinler`<error-category>.errors.yaml` file, and define any metadata in the
1750a2c1a23SMatt Spinler`<error-category>.metadata.yaml` file in the appropriate `*-dbus-interfaces`
1760a2c1a23SMatt Spinlerrepository. During the build, phosphor-logging generates the elog-errors.hpp
1770a2c1a23SMatt Spinlerfile for use by the calling code.
1780a2c1a23SMatt Spinler
1790a2c1a23SMatt SpinlerIn much the same way, sdbusplus uses the event log definitions to generate an
1800a2c1a23SMatt Spinlererror.hpp file that contains the specific exception. The path of the error.hpp
1810a2c1a23SMatt Spinlermatches the path of the YAML file.
1820a2c1a23SMatt Spinler
1830a2c1a23SMatt SpinlerFor example, if in phosphor-dbus-interfaces there is
18426919f07SPatrick Williams`xyz/openbmc_project/Control/Device.errors.yaml`, the errors that come from that
18526919f07SPatrick Williamsfile will be in the include: `xyz/openbmc_project/Control/Device/error.hpp`.
1860a2c1a23SMatt Spinler
1870a2c1a23SMatt SpinlerIn rare cases, one may want one to define their errors in the same repository
1880a2c1a23SMatt Spinlerthat uses them. To do that, one must:
1890a2c1a23SMatt Spinler
1900a2c1a23SMatt Spinler1. Add the error and metadata YAML files to the repository.
1910a2c1a23SMatt Spinler2. Run the sdbus++ script within the makefile to create the error.hpp and .cpp
1920a2c1a23SMatt Spinler   files from the local YAML, and include the error.cpp file in the application
1930a2c1a23SMatt Spinler   that uses it. See [openpower-occ-control] for an example.
1940a2c1a23SMatt Spinler3. Tell phosphor-logging about the error. This is done by either:
19526919f07SPatrick Williams   - Following the [directions](#adding-application-specific-error-yaml) defined
19626919f07SPatrick Williams     in this README, or
19726919f07SPatrick Williams   - Running the script yourself:
19826919f07SPatrick Williams   1. Run phosphor-logging\'s `elog-gen.py` script on the local yaml to generate
19926919f07SPatrick Williams      an elog-errors.hpp file that just contains the local errors, and check
20026919f07SPatrick Williams      that into the repository and include it where the errors are needed.
2010a2c1a23SMatt Spinler   2. Create a recipe that copies the local YAML files to a place that
20226919f07SPatrick Williams      phosphor-logging can find it during the build. See [here][led-link] for an
20326919f07SPatrick Williams      example.
2040a2c1a23SMatt Spinler
2055effae2dSPatrick Williams#### D-Bus Event Log Creation [deprecated]
20626919f07SPatrick Williams
20772575f51SMatt SpinlerThere is also a [D-Bus method][log-create-link] to create event logs:
20826919f07SPatrick Williams
20926919f07SPatrick Williams- Service: xyz.openbmc_project.Logging
21026919f07SPatrick Williams- Object Path: /xyz/openbmc_project/logging
21126919f07SPatrick Williams- Interface: xyz.openbmc_project.Logging.Create
21226919f07SPatrick Williams- Method: Create
21326919f07SPatrick Williams  - Method Arguments:
21426919f07SPatrick Williams    - Message: The `Message` string property for the
21572575f51SMatt Spinler      `xyz.openbmc_project.Logging.Entry` interface.
21626919f07SPatrick Williams    - Severity: The `severity` property for the
21726919f07SPatrick Williams      `xyz.openbmc_project.Logging.Entry` interface. An
21826919f07SPatrick Williams      `xyz.openbmc_project.Logging.Entry.Level` enum value.
21926919f07SPatrick Williams    - AdditionalData: The `AdditionalData` property for the
22026919f07SPatrick Williams      `xyz.openbmc_project.Logging.Entry` interface, but in a map instead of in
22126919f07SPatrick Williams      a vector of "KEY=VALUE" strings. Example:
22226919f07SPatrick Williams
223140d496eSJagpal Singh Gill```cpp
22472575f51SMatt Spinler    std::map<std::string, std::string> additionalData;
22572575f51SMatt Spinler    additionalData["KEY"] = "VALUE";
22672575f51SMatt Spinler```
22772575f51SMatt Spinler
22826919f07SPatrick WilliamsUnlike the previous APIs where errors could also act as exceptions that could be
22926919f07SPatrick Williamsthrown across D-Bus, this API does not require that the error be defined in the
23026919f07SPatrick Williamserror YAML in the D-Bus interfaces repository so that sdbusplus knows about it.
23126919f07SPatrick WilliamsAdditionally, as this method passes in everything needed to create the event
23226919f07SPatrick Williamslog, the logging daemon doesn't have to know about it ahead of time either.
23372575f51SMatt Spinler
23472575f51SMatt SpinlerThat being said, it is recommended that users of this API still follow some
23526919f07SPatrick Williamsguidelines for the message field, which is normally generated from a combination
23626919f07SPatrick Williamsof the path to the error YAML file and the error name itself. For example, the
23726919f07SPatrick Williams`Timeout` error in `xyz/openbmc_project/Common.errors.yaml` will have a Message
23826919f07SPatrick Williamsproperty of `xyz.openbmc_project.Common.Error.Timeout`.
23972575f51SMatt Spinler
24072575f51SMatt SpinlerThe guidelines are:
24126919f07SPatrick Williams
24272575f51SMatt Spinler1. When it makes sense, one can still use an existing error that has already
24372575f51SMatt Spinler   been defined in an error YAML file, and use the same severity and metadata
24472575f51SMatt Spinler   (AdditionalData) as in the corresponding metadata YAML file.
24572575f51SMatt Spinler
24672575f51SMatt Spinler2. If creating a new error, use the same naming scheme as other errors, which
24772575f51SMatt Spinler   starts with the domain, `xyz.openbmc_project`, `org.open_power`, etc,
24826919f07SPatrick Williams   followed by the capitalized category values, followed by `Error`, followed by
24926919f07SPatrick Williams   the capitalized error name itself, with everything separated by "."s. For
25026919f07SPatrick Williams   example: `xyz.openbmc_project.Some.Category.Error.Name`.
25172575f51SMatt Spinler
25272575f51SMatt Spinler3. If creating a new common error, still add it to the appropriate error and
25372575f51SMatt Spinler   metadata YAML files in the appropriate D-Bus interfaces repository so that
25426919f07SPatrick Williams   others can know about it and use it in the future. This can be done after the
25526919f07SPatrick Williams   fact.
2560a2c1a23SMatt Spinler
25726919f07SPatrick Williams[xyz.openbmc_project.logging.entry]:
25826919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Logging/Entry.interface.yaml
25926919f07SPatrick Williams[xyz.openbmc_project.association.definitions]:
26026919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Association/Definitions.interface.yaml
26126919f07SPatrick Williams[associations-doc]:
26226919f07SPatrick Williams  https://github.com/openbmc/docs/blob/master/architecture/object-mapper.md#associations
26326919f07SPatrick Williams[callout-doc]:
26426919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Common/Callout/README.md
26526919f07SPatrick Williams[xyz.openbmc_project.object.delete]:
26626919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Object/Delete.interface.yaml
26726919f07SPatrick Williams[xyz.openbmc_project.software.version]:
26826919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software/Version.errors.yaml
2690a2c1a23SMatt Spinler[openpower-occ-control]: https://github.com/openbmc/openpower-occ-control
27026919f07SPatrick Williams[led-link]:
27126919f07SPatrick Williams  https://github.com/openbmc/openbmc/tree/master/meta-phosphor/recipes-phosphor/leds
27226919f07SPatrick Williams[log-create-link]:
27326919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Logging/Create.interface.yaml
2740febd26bSDeepak Kodihalli
2759067c077SDeepak Kodihalli## Adding application specific error YAML
27626919f07SPatrick Williams
27726919f07SPatrick Williams- This document captures steps for adding application specific error YAML files
2784e5f521aSMarri Devender Rao  and generating local elog-errors.hpp header file for application use.
27926919f07SPatrick Williams- Should cater for continuous integration (CI) build, bitbake image build, and
2804e5f521aSMarri Devender Rao  local repository build.
2817aafb12eSNagaraju Goruganti
282140d496eSJagpal Singh Gill### Continuous Integration (CI) build
28326919f07SPatrick Williams
28426919f07SPatrick Williams- Make is called on the repository that is modified.
28526919f07SPatrick Williams- Dependent packages are pulled based on the dependency list specified in the
2864e5f521aSMarri Devender Rao  configure.ac script.
2877aafb12eSNagaraju Goruganti
2889067c077SDeepak Kodihalli#### Recipe build
28926919f07SPatrick Williams
29026919f07SPatrick Williams- Native recipes copy error YAML files to shared location.
29126919f07SPatrick Williams- phosphor-logging builds elog-errors.hpp by parsing the error YAML files from
2924e5f521aSMarri Devender Rao  the shared location.
2937aafb12eSNagaraju Goruganti
2949067c077SDeepak Kodihalli#### Local repository build
29526919f07SPatrick Williams
29626919f07SPatrick Williams- Copies local error YAML files to the shared location in SDK
29726919f07SPatrick Williams- Make generates elog-errors.hpp by parsing the error YAML files from the shared
29826919f07SPatrick Williams  location.
2997aafb12eSNagaraju Goruganti
3009067c077SDeepak Kodihalli#### Makefile changes
30126919f07SPatrick Williams
302140d496eSJagpal Singh Gill[Reference](https://github.com/openbmc/openpower-debug-collector/blob/master/Makefile.am)
30326919f07SPatrick Williams
304140d496eSJagpal Singh Gill##### Export error YAML to shared location
3059067c077SDeepak Kodihalli
306140d496eSJagpal Singh Gill##### Modify Makefile.am to export newly added error YAML to shared location
30726919f07SPatrick Williams
308140d496eSJagpal Singh Gill```make
3094e5f521aSMarri Devender Raoyamldir = ${datadir}/phosphor-dbus-yaml/yaml
3104e5f521aSMarri Devender Raonobase_yaml_DATA = \
3114e5f521aSMarri Devender Rao    org/open_power/Host.errors.yaml
3124e5f521aSMarri Devender Rao```
3139067c077SDeepak Kodihalli
3149067c077SDeepak Kodihalli###### Generate elog-errors.hpp using elog parser from SDK location
31526919f07SPatrick Williams
31626919f07SPatrick Williams- Add a conditional check "GEN_ERRORS"
31726919f07SPatrick Williams- Disable the check for recipe bitbake image build
31826919f07SPatrick Williams- Enable it for local repository build
31926919f07SPatrick Williams- If "GEN_ERRORS" is enabled, build generates elog-errors.hpp header file.
32026919f07SPatrick Williams
321140d496eSJagpal Singh Gill```make
3224e5f521aSMarri Devender Rao  # Generate phosphor-logging/elog-errors.hpp
3234e5f521aSMarri Devender Rao  if GEN_ERRORS
3244e5f521aSMarri Devender Rao  ELOG_MAKO ?= elog-gen-template.mako.hpp
3254e5f521aSMarri Devender Rao  ELOG_DIR ?= ${OECORE_NATIVE_SYSROOT}${datadir}/phosphor-logging/elog
3264e5f521aSMarri Devender Rao  ELOG_GEN_DIR ?= ${ELOG_DIR}/tools/
3274e5f521aSMarri Devender Rao  ELOG_MAKO_DIR ?= ${ELOG_DIR}/tools/phosphor-logging/templates/
3284e5f521aSMarri Devender Rao  YAML_DIR ?= ${OECORE_NATIVE_SYSROOT}${datadir}/phosphor-dbus-yaml/yaml
3294e5f521aSMarri Devender Rao  phosphor-logging/elog-errors.hpp:
3304e5f521aSMarri Devender Rao      @mkdir -p ${YAML_DIR}/org/open_power/
3314e5f521aSMarri Devender Rao      @cp ${top_srcdir}/org/open_power/Host.errors.yaml \
3324e5f521aSMarri Devender Rao        ${YAML_DIR}/org/open_power/Host.errors.yaml
3334e5f521aSMarri Devender Rao      @mkdir -p `dirname $@`
3344e5f521aSMarri Devender Rao      @chmod 777 $(ELOG_GEN_DIR)/elog-gen.py
3354e5f521aSMarri Devender Rao      $(AM_V_at)$(PYTHON) $(ELOG_GEN_DIR)/elog-gen.py -y ${YAML_DIR} \
3364e5f521aSMarri Devender Rao        -t ${ELOG_MAKO_DIR} -m ${ELOG_MAKO} -o $@
3374e5f521aSMarri Devender Rao  endif
3384e5f521aSMarri Devender Rao```
3397aafb12eSNagaraju Goruganti
3409067c077SDeepak Kodihalli###### Update BUILT_SOURCES
34126919f07SPatrick Williams
34226919f07SPatrick Williams- Append elog-errors.hpp to BUILT_SOURCES list and put it in conditional check
3434e5f521aSMarri Devender Rao  GEN_ERRORS so that the elog-errors.hpp is generated only during local
3444e5f521aSMarri Devender Rao  repository build.
34526919f07SPatrick Williams
346140d496eSJagpal Singh Gill```make
3474e5f521aSMarri Devender Rao    if GEN_ERRORS
3484e5f521aSMarri Devender Rao    nobase_nodist_include_HEADERS += \
3494e5f521aSMarri Devender Rao                phosphor-logging/elog-errors.hpp
3504e5f521aSMarri Devender Rao    endif
3514e5f521aSMarri Devender Rao    if GEN_ERRORS
3524e5f521aSMarri Devender Rao    BUILT_SOURCES += phosphor-logging/elog-errors.hpp
3534e5f521aSMarri Devender Rao    endif
3544e5f521aSMarri Devender Rao```
3559067c077SDeepak Kodihalli
3569067c077SDeepak Kodihalli###### Conditional check for native build
35726919f07SPatrick Williams
35826919f07SPatrick Williams- As the same Makefile is used both for recipe image build and native recipe
3594e5f521aSMarri Devender Rao  build, add a conditional to ensure that only installation of error yaml files
3604e5f521aSMarri Devender Rao  happens during native build. It is not required to build repository during
3614e5f521aSMarri Devender Rao  native build.
36226919f07SPatrick Williams
363140d496eSJagpal Singh Gill```make
3644e5f521aSMarri Devender Rao   if !INSTALL_ERROR_YAML
3654e5f521aSMarri Devender Rao   endif
3664e5f521aSMarri Devender Rao```
3679067c077SDeepak Kodihalli
3689067c077SDeepak Kodihalli#### Autotools changes
36926919f07SPatrick Williams
370140d496eSJagpal Singh Gill[Reference](https://github.com/openbmc/openpower-debug-collector/blob/master/configure.ac)
37126919f07SPatrick Williams
372140d496eSJagpal Singh Gill##### Add option(argument) to enable/disable installing error yaml file
3734e5f521aSMarri Devender Rao
37426919f07SPatrick Williams- Install error yaml option(argument) is enabled for native recipe build and
37526919f07SPatrick Williams  disabled for bitbake build.
37626919f07SPatrick Williams
37726919f07SPatrick Williams- When install error yaml option is disabled do not check for target specific
3784e5f521aSMarri Devender Rao  packages in autotools configure script.
3794e5f521aSMarri Devender Rao
3809067c077SDeepak Kodihalli###### Add option(argument) to install error yaml files
38126919f07SPatrick Williams
382140d496eSJagpal Singh Gill```autoconf
3834e5f521aSMarri Devender RaoAC_ARG_ENABLE([install_error_yaml],
3844e5f521aSMarri Devender Rao    AS_HELP_STRING([--enable-install_error_yaml],
3854e5f521aSMarri Devender Rao    [Enable installing error yaml file]),[], [install_error_yaml=no])
3864e5f521aSMarri Devender RaoAM_CONDITIONAL([INSTALL_ERROR_YAML],
3874e5f521aSMarri Devender Rao    [test "x$enable_install_error_yaml" = "xyes"])
3884e5f521aSMarri Devender RaoAS_IF([test "x$enable_install_error_yaml" != "xyes"], [
3894e5f521aSMarri Devender Rao..
3904e5f521aSMarri Devender Rao..
3914e5f521aSMarri Devender Rao])
3924e5f521aSMarri Devender Rao```
3939067c077SDeepak Kodihalli
3949067c077SDeepak Kodihalli###### Add option(argument) to enable/disable generating elog-errors header file
39526919f07SPatrick Williams
396140d496eSJagpal Singh Gill```autoconf
3974e5f521aSMarri Devender RaoAC_ARG_ENABLE([gen_errors],
3984e5f521aSMarri Devender Rao    AS_HELP_STRING([--enable-gen_errors], [Enable elog-errors.hpp generation ]),
3994e5f521aSMarri Devender Rao    [],[gen_errors=yes])
4004e5f521aSMarri Devender RaoAM_CONDITIONAL([GEN_ERRORS], [test "x$enable_gen_errors" != "xno"])
4014e5f521aSMarri Devender Rao```
4024e5f521aSMarri Devender Rao
4039067c077SDeepak Kodihalli#### Recipe changes
40426919f07SPatrick Williams
405140d496eSJagpal Singh Gill[Reference](https://github.com/openbmc/openbmc/blob/master/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/debug/openpower-debug-collector.bb)
40626919f07SPatrick Williams
407140d496eSJagpal Singh Gill##### Extend recipe for native and nativesdk
40826919f07SPatrick Williams
40926919f07SPatrick Williams- Extend the recipe for native and native SDK builds
41026919f07SPatrick Williams
411140d496eSJagpal Singh Gill```BitBake
4124e5f521aSMarri Devender RaoBBCLASSEXTEND += "native nativesdk"
4134e5f521aSMarri Devender Rao```
41426919f07SPatrick Williams
4159067c077SDeepak Kodihalli###### Remove dependencies for native and native SDK build
41626919f07SPatrick Williams
41726919f07SPatrick Williams- Native recipe caters only for copying error yaml files to shared location.
41826919f07SPatrick Williams- For native and native SDK build remove dependency on packages that recipe
4194e5f521aSMarri Devender Rao  build depends
4204e5f521aSMarri Devender Rao
4219067c077SDeepak Kodihalli###### Remove dependency on phosphor-logging for native build
42226919f07SPatrick Williams
423140d496eSJagpal Singh Gill```BitBake
4244e5f521aSMarri Devender RaoDEPENDS_remove_class-native = "phosphor-logging"
4254e5f521aSMarri Devender Rao```
4269067c077SDeepak Kodihalli
4279067c077SDeepak Kodihalli###### Remove dependency on phosphor-logging for native SDK build
42826919f07SPatrick Williams
429140d496eSJagpal Singh Gill```BitBake
4304e5f521aSMarri Devender RaoDEPENDS_remove_class-nativesdk = "phosphor-logging"
4314e5f521aSMarri Devender Rao```
4329067c077SDeepak Kodihalli
4339067c077SDeepak Kodihalli###### Add install_error_yaml argument during native build
43426919f07SPatrick Williams
43526919f07SPatrick Williams- Add package config to enable/disable install_error_yaml feature.
4369067c077SDeepak Kodihalli
4379067c077SDeepak Kodihalli###### Add package config to enable/disable install_error_yaml feature
43826919f07SPatrick Williams
439140d496eSJagpal Singh Gill```BitBake
4404e5f521aSMarri Devender RaoPACKAGECONFIG ??= "install_error_yaml"
4414e5f521aSMarri Devender RaoPACKAGECONFIG[install_error_yaml] = " \
4424e5f521aSMarri Devender Rao        --enable-install_error_yaml, \
4434e5f521aSMarri Devender Rao        --disable-install_error_yaml, ,\
4444e5f521aSMarri Devender Rao        "
4454e5f521aSMarri Devender Rao```
44626919f07SPatrick Williams
4479067c077SDeepak Kodihalli###### Enable install_error_yaml check for native build
44826919f07SPatrick Williams
449140d496eSJagpal Singh Gill```BitBake
4504e5f521aSMarri Devender RaoPACKAGECONFIG_add_class-native = "install_error_yaml"
4514e5f521aSMarri Devender RaoPACKAGECONFIG_add_class-nativesdk = "install_error_yaml"
4524e5f521aSMarri Devender Rao```
45326919f07SPatrick Williams
4549067c077SDeepak Kodihalli###### Disable install_error_yaml during target build
45526919f07SPatrick Williams
456140d496eSJagpal Singh Gill```BitBake
4574e5f521aSMarri Devender RaoPACKAGECONFIG_remove_class-target = "install_error_yaml"
4584e5f521aSMarri Devender Rao```
4594e5f521aSMarri Devender Rao
4609067c077SDeepak Kodihalli###### Disable generating elog-errors.hpp for bitbake build
46126919f07SPatrick Williams
46226919f07SPatrick Williams- Disable gen_errors argument for bitbake image build as the application uses
4634e5f521aSMarri Devender Rao  the elog-errors.hpp generated by phosphor-logging
46426919f07SPatrick Williams- Argument is enabled by default for local repository build in the configure
4654e5f521aSMarri Devender Rao  script of the local repository.
46626919f07SPatrick Williams
467140d496eSJagpal Singh Gill```BitBake
4684e5f521aSMarri Devender Rao XTRA_OECONF += "--disable-gen_errors"
4694e5f521aSMarri Devender Rao```
4704e5f521aSMarri Devender Rao
4719067c077SDeepak Kodihalli#### Local build
47226919f07SPatrick Williams
47326919f07SPatrick Williams- During local build use --prefix=/usr for the configure script.
4744e5f521aSMarri Devender Rao
475140d496eSJagpal Singh Gill[Reference](https://github.com/openbmc/openpower-debug-collector/blob/master/README.md)
4763210a9f3SMatt Spinler
47799c2b405SMatt Spinler## Event Log Extensions
47899c2b405SMatt Spinler
47926919f07SPatrick WilliamsThe extension concept is a way to allow code that creates other formats of error
48026919f07SPatrick Williamslogs besides phosphor-logging's event logs to still reside in the
48199c2b405SMatt Spinlerphosphor-log-manager application.
48299c2b405SMatt Spinler
48326919f07SPatrick WilliamsThe extension code lives in the `extensions/<extension>` subdirectories, and is
48426919f07SPatrick Williamsenabled with a `--enable-<extension>` configure flag. The extension code won't
48526919f07SPatrick Williamscompile unless enabled with this flag.
48699c2b405SMatt Spinler
48799c2b405SMatt SpinlerExtensions can register themselves to have functions called at the following
48899c2b405SMatt Spinlerpoints using the REGISTER_EXTENSION_FUNCTION macro.
48926919f07SPatrick Williams
49026919f07SPatrick Williams- On startup
49126919f07SPatrick Williams  - Function type void(internal::Manager&)
49226919f07SPatrick Williams- After an event log is created
49326919f07SPatrick Williams  - Function type void(args)
49426919f07SPatrick Williams  - The args are:
49526919f07SPatrick Williams    - const std::string& - The Message property
49626919f07SPatrick Williams    - uin32_t - The event log ID
49726919f07SPatrick Williams    - uint64_t - The event log timestamp
49826919f07SPatrick Williams    - Level - The event level
49926919f07SPatrick Williams    - const AdditionalDataArg& - the additional data
50026919f07SPatrick Williams    - const AssociationEndpointsArg& - Association endpoints (callouts)
50126919f07SPatrick Williams- Before an event log is deleted, to check if it is allowed.
50226919f07SPatrick Williams  - Function type void(std::uint32_t, bool&) that takes the event ID
50326919f07SPatrick Williams- After an event log is deleted
50426919f07SPatrick Williams  - Function type void(std::uint32_t) that takes the event ID
50599c2b405SMatt Spinler
50699c2b405SMatt SpinlerUsing these callback points, they can create their own event log for each
50799c2b405SMatt SpinlerOpenBMC event log that is created, and delete these logs when the corresponding
50899c2b405SMatt SpinlerOpenBMC event log is deleted.
50999c2b405SMatt Spinler
51026919f07SPatrick WilliamsIn addition, an extension has the option of disabling phosphor-logging's default
51126919f07SPatrick Williamserror log capping policy so that it can use its own. The macro
51299c2b405SMatt SpinlerDISABLE_LOG_ENTRY_CAPS() is used for that.
51399c2b405SMatt Spinler
51499c2b405SMatt Spinler### Motivation
51599c2b405SMatt Spinler
51699c2b405SMatt SpinlerThe reason for adding support for extensions inside the phosphor-log-manager
51799c2b405SMatt Spinlerdaemon as opposed to just creating new daemons that listen for D-Bus signals is
51899c2b405SMatt Spinlerto allow interactions that would be complicated or expensive if just done over
51999c2b405SMatt SpinlerD-Bus, such as:
52026919f07SPatrick Williams
52126919f07SPatrick Williams- Allowing for custom old log retention algorithms.
52226919f07SPatrick Williams- Prohibiting manual deleting of certain logs based on an extension's
52399c2b405SMatt Spinler  requirements.
52499c2b405SMatt Spinler
52599c2b405SMatt Spinler### Creating extensions
52699c2b405SMatt Spinler
52799c2b405SMatt Spinler1. Add a new flag to configure.ac to enable the extension:
52826919f07SPatrick Williams
529140d496eSJagpal Singh Gill   ```autoconf
53099c2b405SMatt Spinler   AC_ARG_ENABLE([foo-extension],
53199c2b405SMatt Spinler                 AS_HELP_STRING([--enable-foo-extension],
53299c2b405SMatt Spinler                                [Create Foo logs]))
53399c2b405SMatt Spinler   AM_CONDITIONAL([ENABLE_FOO_EXTENSION],
53499c2b405SMatt Spinler                  [test "x$enable_foo_extension" == "xyes"])
53599c2b405SMatt Spinler   ```
53626919f07SPatrick Williams
53799c2b405SMatt Spinler2. Add the code in `extensions/<extension>/`.
53899c2b405SMatt Spinler3. Create a makefile include to add the new code to phosphor-log-manager:
53926919f07SPatrick Williams
540140d496eSJagpal Singh Gill   ```make
54199c2b405SMatt Spinler   phosphor_log_manager_SOURCES += \
54299c2b405SMatt Spinler           extensions/foo/foo.cpp
54399c2b405SMatt Spinler   ```
54426919f07SPatrick Williams
5455cabd090SAndrew Geissler4. In `extensions/extensions.mk`, add the makefile include:
54626919f07SPatrick Williams
547140d496eSJagpal Singh Gill   ```make
54899c2b405SMatt Spinler   if ENABLE_FOO_EXTENSION
54999c2b405SMatt Spinler   include extensions/foo/foo.mk
55099c2b405SMatt Spinler   endif
55199c2b405SMatt Spinler   ```
55226919f07SPatrick Williams
5535cabd090SAndrew Geissler5. In the extension code, register the functions to call and optionally disable
55499c2b405SMatt Spinler   log capping using the provided macros:
55526919f07SPatrick Williams
556140d496eSJagpal Singh Gill   ```cpp
55799c2b405SMatt Spinler   DISABLE_LOG_ENTRY_CAPS();
55899c2b405SMatt Spinler
55999c2b405SMatt Spinler   void fooStartup(internal::Manager& manager)
56099c2b405SMatt Spinler   {
56199c2b405SMatt Spinler       // Initialize
56299c2b405SMatt Spinler   }
56399c2b405SMatt Spinler
56499c2b405SMatt Spinler   REGISTER_EXTENSION_FUNCTION(fooStartup);
56599c2b405SMatt Spinler
56699c2b405SMatt Spinler   void fooCreate(const std::string& message, uint32_t id, uint64_t timestamp,
56799c2b405SMatt Spinler                   Entry::Level severity, const AdditionalDataArg& additionalData,
56899c2b405SMatt Spinler                   const AssociationEndpointsArg& assocs)
56999c2b405SMatt Spinler   {
57099c2b405SMatt Spinler       // Create a different type of error log based on 'entry'.
57199c2b405SMatt Spinler   }
57299c2b405SMatt Spinler
57399c2b405SMatt Spinler   REGISTER_EXTENSION_FUNCTION(fooCreate);
57499c2b405SMatt Spinler
57599c2b405SMatt Spinler   void fooRemove(uint32_t id)
57699c2b405SMatt Spinler   {
57799c2b405SMatt Spinler       // Delete the extension error log that corresponds to 'id'.
57899c2b405SMatt Spinler   }
57999c2b405SMatt Spinler
58099c2b405SMatt Spinler   REGISTER_EXTENSION_FUNCTION(fooRemove);
58199c2b405SMatt Spinler   ```
58226919f07SPatrick Williams
5833210a9f3SMatt Spinler### Extension List
58499c2b405SMatt Spinler
5853210a9f3SMatt SpinlerThe supported extensions are:
5863210a9f3SMatt Spinler
58726919f07SPatrick Williams- OpenPower PELs
58826919f07SPatrick Williams  - Enabled with --enable-openpower-pel-extension
58926919f07SPatrick Williams  - Detailed information can be found
5903210a9f3SMatt Spinler    [here](extensions/openpower-pels/README.md)
5910649b985SAndrew Geissler
59224eb160fSJeremy Kerr## Remote Logging via Rsyslog
59324eb160fSJeremy Kerr
59426919f07SPatrick WilliamsThe BMC has the ability to stream out local logs (that go to the systemd
595140d496eSJagpal Singh Gilljournal) via rsyslog (<https://www.rsyslog.com/>).
59626919f07SPatrick Williams
59726919f07SPatrick WilliamsThe BMC will send everything. Any kind of filtering and appropriate storage will
59826919f07SPatrick Williamshave to be managed on the rsyslog server. Various examples are available on the
59926919f07SPatrick Williamsinternet. Here are few pointers :
600140d496eSJagpal Singh Gill<https://www.rsyslog.com/storing-and-forwarding-remote-messages/>
601140d496eSJagpal Singh Gill<https://www.rsyslog.com/doc/rsyslog%255Fconf%255Ffilter.html>
602140d496eSJagpal Singh Gill<https://www.thegeekdiary.com/understanding-rsyslog-filter-options/>
60324eb160fSJeremy Kerr
604140d496eSJagpal Singh Gill### Configuring rsyslog server for remote logging
60526919f07SPatrick Williams
60624eb160fSJeremy KerrThe BMC is an rsyslog client. To stream out logs, it needs to talk to an rsyslog
60724eb160fSJeremy Kerrserver, to which there's connectivity over a network. REST API can be used to
60824eb160fSJeremy Kerrset the remote server's IP address and port number.
60924eb160fSJeremy Kerr
61024eb160fSJeremy KerrThe following presumes a user has logged on to the BMC (see
611140d496eSJagpal Singh Gill<https://github.com/openbmc/docs/blob/master/rest-api.md>).
61224eb160fSJeremy Kerr
61324eb160fSJeremy KerrSet the IP:
61426919f07SPatrick Williams
615140d496eSJagpal Singh Gill```sh
61624eb160fSJeremy Kerrcurl -b cjar -k -H "Content-Type: application/json" -X PUT \
61724eb160fSJeremy Kerr    -d '{"data": <IP address>}' \
61824eb160fSJeremy Kerr    https://<BMC IP address>/xyz/openbmc_project/logging/config/remote/attr/Address
61924eb160fSJeremy Kerr```
62024eb160fSJeremy Kerr
62124eb160fSJeremy KerrSet the port:
62226919f07SPatrick Williams
623140d496eSJagpal Singh Gill```sh
62424eb160fSJeremy Kerrcurl -b cjar -k -H "Content-Type: application/json" -X PUT \
62524eb160fSJeremy Kerr    -d '{"data": <port number>}' \
62624eb160fSJeremy Kerr    https://<BMC IP address>/xyz/openbmc_project/logging/config/remote/attr/Port
62724eb160fSJeremy Kerr```
62824eb160fSJeremy Kerr
62924eb160fSJeremy Kerr#### Querying the current configuration
63026919f07SPatrick Williams
631140d496eSJagpal Singh Gill```sh
63224eb160fSJeremy Kerrcurl -b cjar -k \
63324eb160fSJeremy Kerr    https://<BMC IP address>/xyz/openbmc_project/logging/config/remote
63424eb160fSJeremy Kerr```
63524eb160fSJeremy Kerr
63624eb160fSJeremy Kerr#### Setting the hostname
63726919f07SPatrick Williams
63824eb160fSJeremy KerrRsyslog can store logs separately for each host. For this reason, it's useful to
63924eb160fSJeremy Kerrprovide a unique hostname to each managed BMC. Here's how that can be done via a
64024eb160fSJeremy KerrREST API :
64126919f07SPatrick Williams
642140d496eSJagpal Singh Gill```sh
64324eb160fSJeremy Kerrcurl -b cjar -k -H "Content-Type: application/json" -X PUT \
64424eb160fSJeremy Kerr    -d '{"data": "myHostName"}' \
64524eb160fSJeremy Kerr    https://<BMC IP address>//xyz/openbmc_project/network/config/attr/HostName
64624eb160fSJeremy Kerr```
64724eb160fSJeremy Kerr
64824eb160fSJeremy Kerr#### Disabling remote logging
64926919f07SPatrick Williams
65024eb160fSJeremy KerrRemote logging can be disabled by writing 0 to the port, or an empty string("")
65124eb160fSJeremy Kerrto the IP.
65224eb160fSJeremy Kerr
65324eb160fSJeremy Kerr#### Changing the rsyslog server
65426919f07SPatrick Williams
65524eb160fSJeremy KerrWhen switching to a new server from an existing one (i.e the address, or port,
65624eb160fSJeremy Kerror both change), it is recommended to disable the existing configuration first.
65724eb160fSJeremy Kerr
6580649b985SAndrew Geissler## Boot Fail on Hardware Errors
6590649b985SAndrew Geissler
66026919f07SPatrick Williamsphosphor-logging supports a setting, which when set, will result in the software
66126919f07SPatrick Williamslooking at new phosphor-logging entries being created, and if a CALLOUT\* is
66226919f07SPatrick Williamsfound within the entry, ensuring the system will not power on. Entries with
66326919f07SPatrick Williamsseverities of Informational or Debug will not block boots, even if they have
66426919f07SPatrick Williamscallouts.
6650649b985SAndrew Geissler
6660649b985SAndrew GeisslerThe full design for this can be found
6670649b985SAndrew Geissler[here](https://github.com/openbmc/docs/blob/master/designs/fail-boot-on-hw-error.md)
6680649b985SAndrew Geissler
6690649b985SAndrew GeisslerTo enable this function:
6700649b985SAndrew Geissler
671140d496eSJagpal Singh Gill```sh
6720649b985SAndrew Geisslerbusctl set-property xyz.openbmc_project.Settings /xyz/openbmc_project/logging/settings xyz.openbmc_project.Logging.Settings QuiesceOnHwError b true
6730649b985SAndrew Geissler```
6740649b985SAndrew Geissler
6750649b985SAndrew GeisslerTo check if an entry is blocking the boot:
67626919f07SPatrick Williams
677140d496eSJagpal Singh Gill```sh
6780649b985SAndrew Geisslerobmcutil listbootblock
6790649b985SAndrew Geissler```
6800649b985SAndrew Geissler
6810649b985SAndrew GeisslerResolve or clear the corresponding entry to allow the system to boot.
682