xref: /openbmc/phosphor-logging/README.md (revision 26919f07088bc9335e9280c19c94ec147a2d5e5e)
17aafb12eSNagaraju Goruganti# phosphor-logging
2*26919f07SPatrick Williams
3c41693c6SMatt SpinlerThe phosphor logging repository provides mechanisms for event and journal
4c41693c6SMatt Spinlerlogging.
5c41693c6SMatt Spinler
6c41693c6SMatt Spinler## Table Of Contents
7*26919f07SPatrick Williams
8*26919f07SPatrick Williams- [Building](#to-build)
9*26919f07SPatrick Williams- [Structured Logging](#structured-logging)
10*26919f07SPatrick Williams- [Event Logs](#event-logs)
11*26919f07SPatrick Williams- [Application Specific Error YAML](#adding-application-specific-error-yaml)
12*26919f07SPatrick Williams- [Event Log Extensions](#event-log-extensions)
13*26919f07SPatrick Williams- [Remote Logging](#remote-logging-via-rsyslog)
14*26919f07SPatrick Williams- [Boot Fail on Hardware Errors](#boot-fail-on-hardware-errors)
157aafb12eSNagaraju Goruganti
167aafb12eSNagaraju Goruganti## To Build
17*26919f07SPatrick 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
25*26919f07SPatrick Williamsphosphor-logging provides APIs to add program logging information to the
26*26919f07SPatrick Williamssystemd-journal and it is preferred that this logging data is formatted in a
27*26919f07SPatrick Williamsstructured manner (using the facilities provided by the APIs).
28*26919f07SPatrick Williams
29*26919f07SPatrick WilliamsSee [Structured Logging](./docs/structured-logging.md) for more details on this
30*26919f07SPatrick WilliamsAPI.
3187896d58SPatrick Williams
320a2c1a23SMatt Spinler## Event Logs
33*26919f07SPatrick 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
40*26919f07SPatrick Williams- [xyz.openbmc_project.Logging.Entry]
41*26919f07SPatrick Williams  - The main event log interface.
42*26919f07SPatrick Williams- [xyz.openbmc_project.Association.Definitions]
43*26919f07SPatrick Williams  - Used for specifying inventory items as the cause of the event.
44*26919f07SPatrick Williams  - For more information on associations, see [here][associations-doc].
45*26919f07SPatrick Williams- [xyz.openbmc_project.Object.Delete]
46*26919f07SPatrick Williams  - Provides a Delete method to delete the event.
47*26919f07SPatrick Williams- [xyz.openbmc_project.Software.Version]
48*26919f07SPatrick Williams  - Stores the code version that the error occurred on.
49*26919f07SPatrick Williams
50*26919f07SPatrick WilliamsOn platforms that make use of these event logs, the intent is that they are the
51*26919f07SPatrick Williamscommon event log representation that other types of event logs can be created
52*26919f07SPatrick Williamsfrom. For example, there is code to convert these into both Redfish and IPMI
53*26919f07SPatrick Williamsevent logs, in addition to the event log extensions mentioned
540a2c1a23SMatt Spinler[below](#event-log-extensions).
550a2c1a23SMatt Spinler
56*26919f07SPatrick WilliamsThe logging daemon has the ability to add `callout` associations to an event log
57*26919f07SPatrick 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
62*26919f07SPatrick Williams
63*26919f07SPatrick WilliamsThere are two approaches to creating event logs in OpenBMC code. The first makes
64*26919f07SPatrick Williamsuse of the systemd journal to store metadata needed for the log, and the second
65*26919f07SPatrick Williamsis a plain D-Bus method call.
660a2c1a23SMatt Spinler
670a2c1a23SMatt Spinler#### Journal Based Event Log Creation
68*26919f07SPatrick Williams
690a2c1a23SMatt SpinlerEvent logs can be created by using phosphor-logging APIs to commit sdbusplus
70*26919f07SPatrick Williamsexceptions. These APIs write to the journal, and then call a `Commit` D-Bus
71*26919f07SPatrick Williamsmethod on the logging daemon to create the event log using the information it
72*26919f07SPatrick Williamsput in the journal.
730a2c1a23SMatt Spinler
740a2c1a23SMatt SpinlerThe APIs are found in `<phosphor-logging/elog.hpp>`:
75*26919f07SPatrick Williams
76*26919f07SPatrick Williams- `elog()`: Throw an sdbusplus error.
77*26919f07SPatrick Williams- `commit()`: Catch an error thrown by elog(), and commit it to create the event
78*26919f07SPatrick Williams  log.
79*26919f07SPatrick Williams- `report()`: Create an event log from an sdbusplus error without throwing the
800a2c1a23SMatt Spinler  exception first.
810a2c1a23SMatt Spinler
82*26919f07SPatrick WilliamsAny errors passed into these APIs must be known to phosphor-logging, usually by
83*26919f07SPatrick Williamsbeing defined in `<phosphor-logging/elog-errors.hpp>`. The errors must also be
84*26919f07SPatrick Williamsknown by sdbusplus, and be defined in their corresponding error.hpp. See below
85*26919f07SPatrick Williamsfor details on how get errors into these headers.
860a2c1a23SMatt Spinler
870a2c1a23SMatt SpinlerExample:
88*26919f07SPatrick Williams
890a2c1a23SMatt Spinler```
900a2c1a23SMatt Spinler#include <phosphor-logging/elog-errors.hpp>
910a2c1a23SMatt Spinler#include <phosphor-logging/elog.hpp>
920a2c1a23SMatt Spinler#include <xyz/openbmc_project/Common/error.hpp>
930a2c1a23SMatt Spinler...
940a2c1a23SMatt Spinlerusing InternalFailure =
950a2c1a23SMatt Spinler    sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
960a2c1a23SMatt Spinler...
970a2c1a23SMatt Spinlerif (somethingBadHappened)
980a2c1a23SMatt Spinler{
990a2c1a23SMatt Spinler    phosphor::logging::report<InternalFailure>();
1000a2c1a23SMatt Spinler}
1010a2c1a23SMatt Spinler
1020a2c1a23SMatt Spinler```
103*26919f07SPatrick Williams
1040a2c1a23SMatt SpinlerAlternatively, to throw, catch, and then commit the error:
105*26919f07SPatrick Williams
1060a2c1a23SMatt Spinler```
1070a2c1a23SMatt Spinlertry
1080a2c1a23SMatt Spinler{
1090a2c1a23SMatt Spinler    phosphor::logging::elog<InternalFailure>();
1100a2c1a23SMatt Spinler}
1110a2c1a23SMatt Spinlercatch (InternalFailure& e)
1120a2c1a23SMatt Spinler{
1130a2c1a23SMatt Spinler    phosphor::logging::commit<InternalFailure>();
1140a2c1a23SMatt Spinler}
1150a2c1a23SMatt Spinler```
1160a2c1a23SMatt Spinler
1170a2c1a23SMatt SpinlerMetadata can be added to event logs to add debug data captured at the time of
1180a2c1a23SMatt Spinlerthe event. It shows up in the AdditionalData property in the
1190a2c1a23SMatt Spinler`xyz.openbmc_project.Logging.Entry` interface. Metadata is passed in via the
1200a2c1a23SMatt Spinler`elog()` or `report()` functions, which write it to the journal. The metadata
1210a2c1a23SMatt Spinlermust be predefined for the error in the [metadata YAML](#event-log-definition)
122*26919f07SPatrick Williamsso that the daemon knows to look for it in the journal when it creates the event
123*26919f07SPatrick Williamslog.
1240a2c1a23SMatt Spinler
1250a2c1a23SMatt SpinlerExample:
126*26919f07SPatrick Williams
1270a2c1a23SMatt Spinler```
1280a2c1a23SMatt Spinler#include <phosphor-logging/elog-errors.hpp>
1290a2c1a23SMatt Spinler#include <phosphor-logging/elog.hpp>
1300a2c1a23SMatt Spinler#include <xyz/openbmc_project/Control/Device/error.hpp>
1310a2c1a23SMatt Spinler...
1320a2c1a23SMatt Spinlerusing WriteFailure =
1330a2c1a23SMatt Spinler    sdbusplus::xyz::openbmc_project::Control::Device::Error::WriteFailure;
1340a2c1a23SMatt Spinlerusing metadata =
1350a2c1a23SMatt Spinler    xyz::openbmc_project::Control::Device::WriteFailure;
1360a2c1a23SMatt Spinler...
1370a2c1a23SMatt Spinlerif (somethingBadHappened)
1380a2c1a23SMatt Spinler{
1390a2c1a23SMatt Spinler    phosphor::logging::report<WriteFailure>(metadata::CALLOUT_ERRNO(5),
1400a2c1a23SMatt Spinler                              metadata::CALLOUT_DEVICE_PATH("some path"));
1410a2c1a23SMatt Spinler}
1420a2c1a23SMatt Spinler```
143*26919f07SPatrick Williams
1440a2c1a23SMatt SpinlerIn the above example, the AdditionalData property would look like:
145*26919f07SPatrick Williams
1460a2c1a23SMatt Spinler```
1470a2c1a23SMatt Spinler["CALLOUT_ERRNO=5", "CALLOUT_DEVICE_PATH=some path"]
1480a2c1a23SMatt Spinler```
149*26919f07SPatrick Williams
1500a2c1a23SMatt SpinlerNote that the metadata fields must be all uppercase.
1510a2c1a23SMatt Spinler
1520a2c1a23SMatt Spinler##### Event Log Definition
153*26919f07SPatrick Williams
1540a2c1a23SMatt SpinlerAs mentioned above, both sdbusplus and phosphor-logging must know about the
1550a2c1a23SMatt Spinlerevent logs in their header files, or the code that uses them will not even
1560a2c1a23SMatt Spinlercompile. The standard way to do this to define the event in the appropriate
1570a2c1a23SMatt Spinler`<error-category>.errors.yaml` file, and define any metadata in the
1580a2c1a23SMatt Spinler`<error-category>.metadata.yaml` file in the appropriate `*-dbus-interfaces`
1590a2c1a23SMatt Spinlerrepository. During the build, phosphor-logging generates the elog-errors.hpp
1600a2c1a23SMatt Spinlerfile for use by the calling code.
1610a2c1a23SMatt Spinler
1620a2c1a23SMatt SpinlerIn much the same way, sdbusplus uses the event log definitions to generate an
1630a2c1a23SMatt Spinlererror.hpp file that contains the specific exception. The path of the error.hpp
1640a2c1a23SMatt Spinlermatches the path of the YAML file.
1650a2c1a23SMatt Spinler
1660a2c1a23SMatt SpinlerFor example, if in phosphor-dbus-interfaces there is
167*26919f07SPatrick Williams`xyz/openbmc_project/Control/Device.errors.yaml`, the errors that come from that
168*26919f07SPatrick Williamsfile will be in the include: `xyz/openbmc_project/Control/Device/error.hpp`.
1690a2c1a23SMatt Spinler
1700a2c1a23SMatt SpinlerIn rare cases, one may want one to define their errors in the same repository
1710a2c1a23SMatt Spinlerthat uses them. To do that, one must:
1720a2c1a23SMatt Spinler
1730a2c1a23SMatt Spinler1. Add the error and metadata YAML files to the repository.
1740a2c1a23SMatt Spinler2. Run the sdbus++ script within the makefile to create the error.hpp and .cpp
1750a2c1a23SMatt Spinler   files from the local YAML, and include the error.cpp file in the application
1760a2c1a23SMatt Spinler   that uses it. See [openpower-occ-control] for an example.
1770a2c1a23SMatt Spinler3. Tell phosphor-logging about the error. This is done by either:
178*26919f07SPatrick Williams   - Following the [directions](#adding-application-specific-error-yaml) defined
179*26919f07SPatrick Williams     in this README, or
180*26919f07SPatrick Williams   - Running the script yourself:
181*26919f07SPatrick Williams   1. Run phosphor-logging\'s `elog-gen.py` script on the local yaml to generate
182*26919f07SPatrick Williams      an elog-errors.hpp file that just contains the local errors, and check
183*26919f07SPatrick Williams      that into the repository and include it where the errors are needed.
1840a2c1a23SMatt Spinler   2. Create a recipe that copies the local YAML files to a place that
185*26919f07SPatrick Williams      phosphor-logging can find it during the build. See [here][led-link] for an
186*26919f07SPatrick Williams      example.
1870a2c1a23SMatt Spinler
1880a2c1a23SMatt Spinler#### D-Bus Event Log Creation
189*26919f07SPatrick Williams
19072575f51SMatt SpinlerThere is also a [D-Bus method][log-create-link] to create event logs:
191*26919f07SPatrick Williams
192*26919f07SPatrick Williams- Service: xyz.openbmc_project.Logging
193*26919f07SPatrick Williams- Object Path: /xyz/openbmc_project/logging
194*26919f07SPatrick Williams- Interface: xyz.openbmc_project.Logging.Create
195*26919f07SPatrick Williams- Method: Create
196*26919f07SPatrick Williams  - Method Arguments:
197*26919f07SPatrick Williams    - Message: The `Message` string property for the
19872575f51SMatt Spinler      `xyz.openbmc_project.Logging.Entry` interface.
199*26919f07SPatrick Williams    - Severity: The `severity` property for the
200*26919f07SPatrick Williams      `xyz.openbmc_project.Logging.Entry` interface. An
201*26919f07SPatrick Williams      `xyz.openbmc_project.Logging.Entry.Level` enum value.
202*26919f07SPatrick Williams    - AdditionalData: The `AdditionalData` property for the
203*26919f07SPatrick Williams      `xyz.openbmc_project.Logging.Entry` interface, but in a map instead of in
204*26919f07SPatrick Williams      a vector of "KEY=VALUE" strings. Example:
205*26919f07SPatrick Williams
20672575f51SMatt Spinler```
20772575f51SMatt Spinler                     std::map<std::string, std::string> additionalData;
20872575f51SMatt Spinler                     additionalData["KEY"] = "VALUE";
20972575f51SMatt Spinler```
21072575f51SMatt Spinler
211*26919f07SPatrick WilliamsUnlike the previous APIs where errors could also act as exceptions that could be
212*26919f07SPatrick Williamsthrown across D-Bus, this API does not require that the error be defined in the
213*26919f07SPatrick Williamserror YAML in the D-Bus interfaces repository so that sdbusplus knows about it.
214*26919f07SPatrick WilliamsAdditionally, as this method passes in everything needed to create the event
215*26919f07SPatrick Williamslog, the logging daemon doesn't have to know about it ahead of time either.
21672575f51SMatt Spinler
21772575f51SMatt SpinlerThat being said, it is recommended that users of this API still follow some
218*26919f07SPatrick Williamsguidelines for the message field, which is normally generated from a combination
219*26919f07SPatrick Williamsof the path to the error YAML file and the error name itself. For example, the
220*26919f07SPatrick Williams`Timeout` error in `xyz/openbmc_project/Common.errors.yaml` will have a Message
221*26919f07SPatrick Williamsproperty of `xyz.openbmc_project.Common.Error.Timeout`.
22272575f51SMatt Spinler
22372575f51SMatt SpinlerThe guidelines are:
224*26919f07SPatrick Williams
22572575f51SMatt Spinler1. When it makes sense, one can still use an existing error that has already
22672575f51SMatt Spinler   been defined in an error YAML file, and use the same severity and metadata
22772575f51SMatt Spinler   (AdditionalData) as in the corresponding metadata YAML file.
22872575f51SMatt Spinler
22972575f51SMatt Spinler2. If creating a new error, use the same naming scheme as other errors, which
23072575f51SMatt Spinler   starts with the domain, `xyz.openbmc_project`, `org.open_power`, etc,
231*26919f07SPatrick Williams   followed by the capitalized category values, followed by `Error`, followed by
232*26919f07SPatrick Williams   the capitalized error name itself, with everything separated by "."s. For
233*26919f07SPatrick Williams   example: `xyz.openbmc_project.Some.Category.Error.Name`.
23472575f51SMatt Spinler
23572575f51SMatt Spinler3. If creating a new common error, still add it to the appropriate error and
23672575f51SMatt Spinler   metadata YAML files in the appropriate D-Bus interfaces repository so that
237*26919f07SPatrick Williams   others can know about it and use it in the future. This can be done after the
238*26919f07SPatrick Williams   fact.
2390a2c1a23SMatt Spinler
240*26919f07SPatrick Williams[xyz.openbmc_project.logging.entry]:
241*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Logging/Entry.interface.yaml
242*26919f07SPatrick Williams[xyz.openbmc_project.association.definitions]:
243*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Association/Definitions.interface.yaml
244*26919f07SPatrick Williams[associations-doc]:
245*26919f07SPatrick Williams  https://github.com/openbmc/docs/blob/master/architecture/object-mapper.md#associations
246*26919f07SPatrick Williams[callout-doc]:
247*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Common/Callout/README.md
248*26919f07SPatrick Williams[xyz.openbmc_project.object.delete]:
249*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Object/Delete.interface.yaml
250*26919f07SPatrick Williams[xyz.openbmc_project.software.version]:
251*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software/Version.errors.yaml
252*26919f07SPatrick Williams[elog-errors.hpp]:
253*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-logging/blob/master/phosphor-logging/elog.hpp
2540a2c1a23SMatt Spinler[openpower-occ-control]: https://github.com/openbmc/openpower-occ-control
255*26919f07SPatrick Williams[led-link]:
256*26919f07SPatrick Williams  https://github.com/openbmc/openbmc/tree/master/meta-phosphor/recipes-phosphor/leds
257*26919f07SPatrick Williams[log-create-link]:
258*26919f07SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Logging/Create.interface.yaml
2590febd26bSDeepak Kodihalli
2609067c077SDeepak Kodihalli## Adding application specific error YAML
261*26919f07SPatrick Williams
262*26919f07SPatrick Williams- This document captures steps for adding application specific error YAML files
2634e5f521aSMarri Devender Rao  and generating local elog-errors.hpp header file for application use.
264*26919f07SPatrick Williams- Should cater for continuous integration (CI) build, bitbake image build, and
2654e5f521aSMarri Devender Rao  local repository build.
2667aafb12eSNagaraju Goruganti
2679067c077SDeepak Kodihalli#### Continuous Integration (CI) build
268*26919f07SPatrick Williams
269*26919f07SPatrick Williams- Make is called on the repository that is modified.
270*26919f07SPatrick Williams- Dependent packages are pulled based on the dependency list specified in the
2714e5f521aSMarri Devender Rao  configure.ac script.
2727aafb12eSNagaraju Goruganti
2739067c077SDeepak Kodihalli#### Recipe build
274*26919f07SPatrick Williams
275*26919f07SPatrick Williams- Native recipes copy error YAML files to shared location.
276*26919f07SPatrick Williams- phosphor-logging builds elog-errors.hpp by parsing the error YAML files from
2774e5f521aSMarri Devender Rao  the shared location.
2787aafb12eSNagaraju Goruganti
2799067c077SDeepak Kodihalli#### Local repository build
280*26919f07SPatrick Williams
281*26919f07SPatrick Williams- Copies local error YAML files to the shared location in SDK
282*26919f07SPatrick Williams- Make generates elog-errors.hpp by parsing the error YAML files from the shared
283*26919f07SPatrick Williams  location.
2847aafb12eSNagaraju Goruganti
2859067c077SDeepak Kodihalli#### Makefile changes
286*26919f07SPatrick Williams
2874e5f521aSMarri Devender Rao**Reference**
288*26919f07SPatrick Williams
289*26919f07SPatrick Williams- https://github.com/openbmc/openpower-debug-collector/blob/master/Makefile.am
2909067c077SDeepak Kodihalli
2919067c077SDeepak Kodihalli###### Export error YAML to shared location
292*26919f07SPatrick Williams
293*26919f07SPatrick Williams_Modify Makefile.am to export newly added error YAML to shared location_
294*26919f07SPatrick Williams
2954e5f521aSMarri Devender Rao```
2964e5f521aSMarri Devender Raoyamldir = ${datadir}/phosphor-dbus-yaml/yaml
2974e5f521aSMarri Devender Raonobase_yaml_DATA = \
2984e5f521aSMarri Devender Rao    org/open_power/Host.errors.yaml
2994e5f521aSMarri Devender Rao```
3009067c077SDeepak Kodihalli
3019067c077SDeepak Kodihalli###### Generate elog-errors.hpp using elog parser from SDK location
302*26919f07SPatrick Williams
303*26919f07SPatrick Williams- Add a conditional check "GEN_ERRORS"
304*26919f07SPatrick Williams- Disable the check for recipe bitbake image build
305*26919f07SPatrick Williams- Enable it for local repository build
306*26919f07SPatrick Williams- If "GEN_ERRORS" is enabled, build generates elog-errors.hpp header file.
307*26919f07SPatrick Williams
3084e5f521aSMarri Devender Rao```
3094e5f521aSMarri Devender Rao  # Generate phosphor-logging/elog-errors.hpp
3104e5f521aSMarri Devender Rao  if GEN_ERRORS
3114e5f521aSMarri Devender Rao  ELOG_MAKO ?= elog-gen-template.mako.hpp
3124e5f521aSMarri Devender Rao  ELOG_DIR ?= ${OECORE_NATIVE_SYSROOT}${datadir}/phosphor-logging/elog
3134e5f521aSMarri Devender Rao  ELOG_GEN_DIR ?= ${ELOG_DIR}/tools/
3144e5f521aSMarri Devender Rao  ELOG_MAKO_DIR ?= ${ELOG_DIR}/tools/phosphor-logging/templates/
3154e5f521aSMarri Devender Rao  YAML_DIR ?= ${OECORE_NATIVE_SYSROOT}${datadir}/phosphor-dbus-yaml/yaml
3164e5f521aSMarri Devender Rao  phosphor-logging/elog-errors.hpp:
3174e5f521aSMarri Devender Rao      @mkdir -p ${YAML_DIR}/org/open_power/
3184e5f521aSMarri Devender Rao      @cp ${top_srcdir}/org/open_power/Host.errors.yaml \
3194e5f521aSMarri Devender Rao        ${YAML_DIR}/org/open_power/Host.errors.yaml
3204e5f521aSMarri Devender Rao      @mkdir -p `dirname $@`
3214e5f521aSMarri Devender Rao      @chmod 777 $(ELOG_GEN_DIR)/elog-gen.py
3224e5f521aSMarri Devender Rao      $(AM_V_at)$(PYTHON) $(ELOG_GEN_DIR)/elog-gen.py -y ${YAML_DIR} \
3234e5f521aSMarri Devender Rao        -t ${ELOG_MAKO_DIR} -m ${ELOG_MAKO} -o $@
3244e5f521aSMarri Devender Rao  endif
3254e5f521aSMarri Devender Rao```
3267aafb12eSNagaraju Goruganti
3279067c077SDeepak Kodihalli###### Update BUILT_SOURCES
328*26919f07SPatrick Williams
329*26919f07SPatrick Williams- Append elog-errors.hpp to BUILT_SOURCES list and put it in conditional check
3304e5f521aSMarri Devender Rao  GEN_ERRORS so that the elog-errors.hpp is generated only during local
3314e5f521aSMarri Devender Rao  repository build.
332*26919f07SPatrick Williams
3334e5f521aSMarri Devender Rao```
3344e5f521aSMarri Devender Rao    if GEN_ERRORS
3354e5f521aSMarri Devender Rao    nobase_nodist_include_HEADERS += \
3364e5f521aSMarri Devender Rao                phosphor-logging/elog-errors.hpp
3374e5f521aSMarri Devender Rao    endif
3384e5f521aSMarri Devender Rao    if GEN_ERRORS
3394e5f521aSMarri Devender Rao    BUILT_SOURCES += phosphor-logging/elog-errors.hpp
3404e5f521aSMarri Devender Rao    endif
3414e5f521aSMarri Devender Rao```
3429067c077SDeepak Kodihalli
3439067c077SDeepak Kodihalli###### Conditional check for native build
344*26919f07SPatrick Williams
345*26919f07SPatrick Williams- As the same Makefile is used both for recipe image build and native recipe
3464e5f521aSMarri Devender Rao  build, add a conditional to ensure that only installation of error yaml files
3474e5f521aSMarri Devender Rao  happens during native build. It is not required to build repository during
3484e5f521aSMarri Devender Rao  native build.
349*26919f07SPatrick Williams
3504e5f521aSMarri Devender Rao```
3514e5f521aSMarri Devender Rao   if !INSTALL_ERROR_YAML
3524e5f521aSMarri Devender Rao   endif
3534e5f521aSMarri Devender Rao```
3549067c077SDeepak Kodihalli
3559067c077SDeepak Kodihalli#### Autotools changes
356*26919f07SPatrick Williams
3574e5f521aSMarri Devender Rao**Reference**
358*26919f07SPatrick Williams
359*26919f07SPatrick Williams- https://github.com/openbmc/openpower-debug-collector/blob/master/configure.ac
3607aafb12eSNagaraju Goruganti
3619067c077SDeepak Kodihalli###### Add option(argument) to enable/disable installing error yaml file
3624e5f521aSMarri Devender Rao
363*26919f07SPatrick Williams- Install error yaml option(argument) is enabled for native recipe build and
364*26919f07SPatrick Williams  disabled for bitbake build.
365*26919f07SPatrick Williams
366*26919f07SPatrick Williams- When install error yaml option is disabled do not check for target specific
3674e5f521aSMarri Devender Rao  packages in autotools configure script.
3684e5f521aSMarri Devender Rao
3699067c077SDeepak Kodihalli###### Add option(argument) to install error yaml files
370*26919f07SPatrick Williams
3714e5f521aSMarri Devender Rao```
3724e5f521aSMarri Devender RaoAC_ARG_ENABLE([install_error_yaml],
3734e5f521aSMarri Devender Rao    AS_HELP_STRING([--enable-install_error_yaml],
3744e5f521aSMarri Devender Rao    [Enable installing error yaml file]),[], [install_error_yaml=no])
3754e5f521aSMarri Devender RaoAM_CONDITIONAL([INSTALL_ERROR_YAML],
3764e5f521aSMarri Devender Rao    [test "x$enable_install_error_yaml" = "xyes"])
3774e5f521aSMarri Devender RaoAS_IF([test "x$enable_install_error_yaml" != "xyes"], [
3784e5f521aSMarri Devender Rao..
3794e5f521aSMarri Devender Rao..
3804e5f521aSMarri Devender Rao])
3814e5f521aSMarri Devender Rao```
3829067c077SDeepak Kodihalli
3839067c077SDeepak Kodihalli###### Add option(argument) to enable/disable generating elog-errors header file
384*26919f07SPatrick Williams
3854e5f521aSMarri Devender Rao```
3864e5f521aSMarri Devender RaoAC_ARG_ENABLE([gen_errors],
3874e5f521aSMarri Devender Rao    AS_HELP_STRING([--enable-gen_errors], [Enable elog-errors.hpp generation ]),
3884e5f521aSMarri Devender Rao    [],[gen_errors=yes])
3894e5f521aSMarri Devender RaoAM_CONDITIONAL([GEN_ERRORS], [test "x$enable_gen_errors" != "xno"])
3904e5f521aSMarri Devender Rao```
3914e5f521aSMarri Devender Rao
3929067c077SDeepak Kodihalli#### Recipe changes
393*26919f07SPatrick Williams
3944e5f521aSMarri Devender Rao**Reference**
395*26919f07SPatrick Williams
396*26919f07SPatrick Williams- https://github.com/openbmc/openbmc/blob/master/meta-openbmc-machines\
3974e5f521aSMarri Devender Rao  /meta-openpower/common/recipes-phosphor/debug/openpower-debug-collector.bb
3984e5f521aSMarri Devender Rao
3999067c077SDeepak Kodihalli###### Extend recipe for native and nativesdk
400*26919f07SPatrick Williams
401*26919f07SPatrick Williams- Extend the recipe for native and native SDK builds
402*26919f07SPatrick Williams
4034e5f521aSMarri Devender Rao```
4044e5f521aSMarri Devender RaoBBCLASSEXTEND += "native nativesdk"
4054e5f521aSMarri Devender Rao```
406*26919f07SPatrick Williams
4079067c077SDeepak Kodihalli###### Remove dependencies for native and native SDK build
408*26919f07SPatrick Williams
409*26919f07SPatrick Williams- Native recipe caters only for copying error yaml files to shared location.
410*26919f07SPatrick Williams- For native and native SDK build remove dependency on packages that recipe
4114e5f521aSMarri Devender Rao  build depends
4124e5f521aSMarri Devender Rao
4139067c077SDeepak Kodihalli###### Remove dependency on phosphor-logging for native build
414*26919f07SPatrick Williams
4154e5f521aSMarri Devender Rao```
4164e5f521aSMarri Devender RaoDEPENDS_remove_class-native = "phosphor-logging"
4174e5f521aSMarri Devender Rao```
4189067c077SDeepak Kodihalli
4199067c077SDeepak Kodihalli###### Remove dependency on phosphor-logging for native SDK build
420*26919f07SPatrick Williams
4214e5f521aSMarri Devender Rao```
4224e5f521aSMarri Devender RaoDEPENDS_remove_class-nativesdk = "phosphor-logging"
4234e5f521aSMarri Devender Rao```
4249067c077SDeepak Kodihalli
4259067c077SDeepak Kodihalli###### Add install_error_yaml argument during native build
426*26919f07SPatrick Williams
427*26919f07SPatrick Williams- Add package config to enable/disable install_error_yaml feature.
4289067c077SDeepak Kodihalli
4299067c077SDeepak Kodihalli###### Add package config to enable/disable install_error_yaml feature
430*26919f07SPatrick Williams
4314e5f521aSMarri Devender Rao```
4324e5f521aSMarri Devender RaoPACKAGECONFIG ??= "install_error_yaml"
4334e5f521aSMarri Devender RaoPACKAGECONFIG[install_error_yaml] = " \
4344e5f521aSMarri Devender Rao        --enable-install_error_yaml, \
4354e5f521aSMarri Devender Rao        --disable-install_error_yaml, ,\
4364e5f521aSMarri Devender Rao        "
4374e5f521aSMarri Devender Rao```
438*26919f07SPatrick Williams
4399067c077SDeepak Kodihalli###### Enable install_error_yaml check for native build
440*26919f07SPatrick Williams
4414e5f521aSMarri Devender Rao```
4424e5f521aSMarri Devender RaoPACKAGECONFIG_add_class-native = "install_error_yaml"
4434e5f521aSMarri Devender RaoPACKAGECONFIG_add_class-nativesdk = "install_error_yaml"
4444e5f521aSMarri Devender Rao```
445*26919f07SPatrick Williams
4469067c077SDeepak Kodihalli###### Disable install_error_yaml during target build
447*26919f07SPatrick Williams
4484e5f521aSMarri Devender Rao```
4494e5f521aSMarri Devender RaoPACKAGECONFIG_remove_class-target = "install_error_yaml"
4504e5f521aSMarri Devender Rao```
4514e5f521aSMarri Devender Rao
4529067c077SDeepak Kodihalli###### Disable generating elog-errors.hpp for bitbake build
453*26919f07SPatrick Williams
454*26919f07SPatrick Williams- Disable gen_errors argument for bitbake image build as the application uses
4554e5f521aSMarri Devender Rao  the elog-errors.hpp generated by phosphor-logging
456*26919f07SPatrick Williams- Argument is enabled by default for local repository build in the configure
4574e5f521aSMarri Devender Rao  script of the local repository.
458*26919f07SPatrick Williams
4594e5f521aSMarri Devender Rao```
4604e5f521aSMarri Devender Rao XTRA_OECONF += "--disable-gen_errors"
4614e5f521aSMarri Devender Rao```
4624e5f521aSMarri Devender Rao
4639067c077SDeepak Kodihalli#### Local build
464*26919f07SPatrick Williams
465*26919f07SPatrick Williams- During local build use --prefix=/usr for the configure script.
4664e5f521aSMarri Devender Rao
4673210a9f3SMatt Spinler**Reference**
468*26919f07SPatrick Williams
469*26919f07SPatrick Williams- https://github.com/openbmc/openpower-debug-collector/blob/master/README.md
4703210a9f3SMatt Spinler
47199c2b405SMatt Spinler## Event Log Extensions
47299c2b405SMatt Spinler
473*26919f07SPatrick WilliamsThe extension concept is a way to allow code that creates other formats of error
474*26919f07SPatrick Williamslogs besides phosphor-logging's event logs to still reside in the
47599c2b405SMatt Spinlerphosphor-log-manager application.
47699c2b405SMatt Spinler
477*26919f07SPatrick WilliamsThe extension code lives in the `extensions/<extension>` subdirectories, and is
478*26919f07SPatrick Williamsenabled with a `--enable-<extension>` configure flag. The extension code won't
479*26919f07SPatrick Williamscompile unless enabled with this flag.
48099c2b405SMatt Spinler
48199c2b405SMatt SpinlerExtensions can register themselves to have functions called at the following
48299c2b405SMatt Spinlerpoints using the REGISTER_EXTENSION_FUNCTION macro.
483*26919f07SPatrick Williams
484*26919f07SPatrick Williams- On startup
485*26919f07SPatrick Williams  - Function type void(internal::Manager&)
486*26919f07SPatrick Williams- After an event log is created
487*26919f07SPatrick Williams  - Function type void(args)
488*26919f07SPatrick Williams  - The args are:
489*26919f07SPatrick Williams    - const std::string& - The Message property
490*26919f07SPatrick Williams    - uin32_t - The event log ID
491*26919f07SPatrick Williams    - uint64_t - The event log timestamp
492*26919f07SPatrick Williams    - Level - The event level
493*26919f07SPatrick Williams    - const AdditionalDataArg& - the additional data
494*26919f07SPatrick Williams    - const AssociationEndpointsArg& - Association endpoints (callouts)
495*26919f07SPatrick Williams- Before an event log is deleted, to check if it is allowed.
496*26919f07SPatrick Williams  - Function type void(std::uint32_t, bool&) that takes the event ID
497*26919f07SPatrick Williams- After an event log is deleted
498*26919f07SPatrick Williams  - Function type void(std::uint32_t) that takes the event ID
49999c2b405SMatt Spinler
50099c2b405SMatt SpinlerUsing these callback points, they can create their own event log for each
50199c2b405SMatt SpinlerOpenBMC event log that is created, and delete these logs when the corresponding
50299c2b405SMatt SpinlerOpenBMC event log is deleted.
50399c2b405SMatt Spinler
504*26919f07SPatrick WilliamsIn addition, an extension has the option of disabling phosphor-logging's default
505*26919f07SPatrick Williamserror log capping policy so that it can use its own. The macro
50699c2b405SMatt SpinlerDISABLE_LOG_ENTRY_CAPS() is used for that.
50799c2b405SMatt Spinler
50899c2b405SMatt Spinler### Motivation
50999c2b405SMatt Spinler
51099c2b405SMatt SpinlerThe reason for adding support for extensions inside the phosphor-log-manager
51199c2b405SMatt Spinlerdaemon as opposed to just creating new daemons that listen for D-Bus signals is
51299c2b405SMatt Spinlerto allow interactions that would be complicated or expensive if just done over
51399c2b405SMatt SpinlerD-Bus, such as:
514*26919f07SPatrick Williams
515*26919f07SPatrick Williams- Allowing for custom old log retention algorithms.
516*26919f07SPatrick Williams- Prohibiting manual deleting of certain logs based on an extension's
51799c2b405SMatt Spinler  requirements.
51899c2b405SMatt Spinler
51999c2b405SMatt Spinler### Creating extensions
52099c2b405SMatt Spinler
52199c2b405SMatt Spinler1. Add a new flag to configure.ac to enable the extension:
522*26919f07SPatrick Williams
52399c2b405SMatt Spinler```
52499c2b405SMatt SpinlerAC_ARG_ENABLE([foo-extension],
52599c2b405SMatt Spinler              AS_HELP_STRING([--enable-foo-extension],
52699c2b405SMatt Spinler                             [Create Foo logs]))
52799c2b405SMatt SpinlerAM_CONDITIONAL([ENABLE_FOO_EXTENSION],
52899c2b405SMatt Spinler               [test "x$enable_foo_extension" == "xyes"])
52999c2b405SMatt Spinler```
530*26919f07SPatrick Williams
53199c2b405SMatt Spinler2. Add the code in `extensions/<extension>/`.
53299c2b405SMatt Spinler3. Create a makefile include to add the new code to phosphor-log-manager:
533*26919f07SPatrick Williams
53499c2b405SMatt Spinler```
53599c2b405SMatt Spinlerphosphor_log_manager_SOURCES += \
53699c2b405SMatt Spinler        extensions/foo/foo.cpp
53799c2b405SMatt Spinler```
538*26919f07SPatrick Williams
5395cabd090SAndrew Geissler4. In `extensions/extensions.mk`, add the makefile include:
540*26919f07SPatrick Williams
54199c2b405SMatt Spinler```
54299c2b405SMatt Spinlerif ENABLE_FOO_EXTENSION
54399c2b405SMatt Spinlerinclude extensions/foo/foo.mk
54499c2b405SMatt Spinlerendif
54599c2b405SMatt Spinler```
546*26919f07SPatrick Williams
5475cabd090SAndrew Geissler5. In the extension code, register the functions to call and optionally disable
54899c2b405SMatt Spinler   log capping using the provided macros:
549*26919f07SPatrick Williams
55099c2b405SMatt Spinler```
55199c2b405SMatt SpinlerDISABLE_LOG_ENTRY_CAPS();
55299c2b405SMatt Spinler
55399c2b405SMatt Spinlervoid fooStartup(internal::Manager& manager)
55499c2b405SMatt Spinler{
55599c2b405SMatt Spinler    // Initialize
55699c2b405SMatt Spinler}
55799c2b405SMatt Spinler
55899c2b405SMatt SpinlerREGISTER_EXTENSION_FUNCTION(fooStartup);
55999c2b405SMatt Spinler
56099c2b405SMatt Spinlervoid fooCreate(const std::string& message, uint32_t id, uint64_t timestamp,
56199c2b405SMatt Spinler               Entry::Level severity, const AdditionalDataArg& additionalData,
56299c2b405SMatt Spinler               const AssociationEndpointsArg& assocs)
56399c2b405SMatt Spinler{
56499c2b405SMatt Spinler    // Create a different type of error log based on 'entry'.
56599c2b405SMatt Spinler}
56699c2b405SMatt Spinler
56799c2b405SMatt SpinlerREGISTER_EXTENSION_FUNCTION(fooCreate);
56899c2b405SMatt Spinler
56999c2b405SMatt Spinlervoid fooRemove(uint32_t id)
57099c2b405SMatt Spinler{
57199c2b405SMatt Spinler    // Delete the extension error log that corresponds to 'id'.
57299c2b405SMatt Spinler}
57399c2b405SMatt Spinler
57499c2b405SMatt SpinlerREGISTER_EXTENSION_FUNCTION(fooRemove);
57599c2b405SMatt Spinler```
576*26919f07SPatrick Williams
5773210a9f3SMatt Spinler### Extension List
57899c2b405SMatt Spinler
5793210a9f3SMatt SpinlerThe supported extensions are:
5803210a9f3SMatt Spinler
581*26919f07SPatrick Williams- OpenPower PELs
582*26919f07SPatrick Williams  - Enabled with --enable-openpower-pel-extension
583*26919f07SPatrick Williams  - Detailed information can be found
5843210a9f3SMatt Spinler    [here](extensions/openpower-pels/README.md)
5850649b985SAndrew Geissler
58624eb160fSJeremy Kerr## Remote Logging via Rsyslog
58724eb160fSJeremy Kerr
588*26919f07SPatrick WilliamsThe BMC has the ability to stream out local logs (that go to the systemd
589*26919f07SPatrick Williamsjournal) via rsyslog (https://www.rsyslog.com/).
590*26919f07SPatrick Williams
591*26919f07SPatrick WilliamsThe BMC will send everything. Any kind of filtering and appropriate storage will
592*26919f07SPatrick Williamshave to be managed on the rsyslog server. Various examples are available on the
593*26919f07SPatrick Williamsinternet. Here are few pointers :
59424eb160fSJeremy Kerrhttps://www.rsyslog.com/storing-and-forwarding-remote-messages/
59524eb160fSJeremy Kerrhttps://www.rsyslog.com/doc/rsyslog%255Fconf%255Ffilter.html
59624eb160fSJeremy Kerrhttps://www.thegeekdiary.com/understanding-rsyslog-filter-options/
59724eb160fSJeremy Kerr
59824eb160fSJeremy Kerr#### Configuring rsyslog server for remote logging
599*26919f07SPatrick Williams
60024eb160fSJeremy KerrThe BMC is an rsyslog client. To stream out logs, it needs to talk to an rsyslog
60124eb160fSJeremy Kerrserver, to which there's connectivity over a network. REST API can be used to
60224eb160fSJeremy Kerrset the remote server's IP address and port number.
60324eb160fSJeremy Kerr
60424eb160fSJeremy KerrThe following presumes a user has logged on to the BMC (see
60524eb160fSJeremy Kerrhttps://github.com/openbmc/docs/blob/master/rest-api.md).
60624eb160fSJeremy Kerr
60724eb160fSJeremy KerrSet the IP:
608*26919f07SPatrick Williams
60924eb160fSJeremy Kerr```
61024eb160fSJeremy Kerrcurl -b cjar -k -H "Content-Type: application/json" -X PUT \
61124eb160fSJeremy Kerr    -d '{"data": <IP address>}' \
61224eb160fSJeremy Kerr    https://<BMC IP address>/xyz/openbmc_project/logging/config/remote/attr/Address
61324eb160fSJeremy Kerr```
61424eb160fSJeremy Kerr
61524eb160fSJeremy KerrSet the port:
616*26919f07SPatrick Williams
61724eb160fSJeremy Kerr```
61824eb160fSJeremy Kerrcurl -b cjar -k -H "Content-Type: application/json" -X PUT \
61924eb160fSJeremy Kerr    -d '{"data": <port number>}' \
62024eb160fSJeremy Kerr    https://<BMC IP address>/xyz/openbmc_project/logging/config/remote/attr/Port
62124eb160fSJeremy Kerr```
62224eb160fSJeremy Kerr
62324eb160fSJeremy Kerr#### Querying the current configuration
624*26919f07SPatrick Williams
62524eb160fSJeremy Kerr```
62624eb160fSJeremy Kerrcurl -b cjar -k \
62724eb160fSJeremy Kerr    https://<BMC IP address>/xyz/openbmc_project/logging/config/remote
62824eb160fSJeremy Kerr```
62924eb160fSJeremy Kerr
63024eb160fSJeremy Kerr#### Setting the hostname
631*26919f07SPatrick Williams
63224eb160fSJeremy KerrRsyslog can store logs separately for each host. For this reason, it's useful to
63324eb160fSJeremy Kerrprovide a unique hostname to each managed BMC. Here's how that can be done via a
63424eb160fSJeremy KerrREST API :
635*26919f07SPatrick Williams
63624eb160fSJeremy Kerr```
63724eb160fSJeremy Kerrcurl -b cjar -k -H "Content-Type: application/json" -X PUT \
63824eb160fSJeremy Kerr    -d '{"data": "myHostName"}' \
63924eb160fSJeremy Kerr    https://<BMC IP address>//xyz/openbmc_project/network/config/attr/HostName
64024eb160fSJeremy Kerr```
64124eb160fSJeremy Kerr
64224eb160fSJeremy Kerr#### Disabling remote logging
643*26919f07SPatrick Williams
64424eb160fSJeremy KerrRemote logging can be disabled by writing 0 to the port, or an empty string("")
64524eb160fSJeremy Kerrto the IP.
64624eb160fSJeremy Kerr
64724eb160fSJeremy Kerr#### Changing the rsyslog server
648*26919f07SPatrick Williams
64924eb160fSJeremy KerrWhen switching to a new server from an existing one (i.e the address, or port,
65024eb160fSJeremy Kerror both change), it is recommended to disable the existing configuration first.
65124eb160fSJeremy Kerr
6520649b985SAndrew Geissler## Boot Fail on Hardware Errors
6530649b985SAndrew Geissler
654*26919f07SPatrick Williamsphosphor-logging supports a setting, which when set, will result in the software
655*26919f07SPatrick Williamslooking at new phosphor-logging entries being created, and if a CALLOUT\* is
656*26919f07SPatrick Williamsfound within the entry, ensuring the system will not power on. Entries with
657*26919f07SPatrick Williamsseverities of Informational or Debug will not block boots, even if they have
658*26919f07SPatrick Williamscallouts.
6590649b985SAndrew Geissler
6600649b985SAndrew GeisslerThe full design for this can be found
6610649b985SAndrew Geissler[here](https://github.com/openbmc/docs/blob/master/designs/fail-boot-on-hw-error.md)
6620649b985SAndrew Geissler
6630649b985SAndrew GeisslerTo enable this function:
6640649b985SAndrew Geissler
6650649b985SAndrew Geissler```
6660649b985SAndrew Geisslerbusctl set-property xyz.openbmc_project.Settings /xyz/openbmc_project/logging/settings xyz.openbmc_project.Logging.Settings QuiesceOnHwError b true
6670649b985SAndrew Geissler```
6680649b985SAndrew Geissler
6690649b985SAndrew GeisslerTo check if an entry is blocking the boot:
670*26919f07SPatrick Williams
6710649b985SAndrew Geissler```
6720649b985SAndrew Geisslerobmcutil listbootblock
6730649b985SAndrew Geissler```
6740649b985SAndrew Geissler
6750649b985SAndrew GeisslerResolve or clear the corresponding entry to allow the system to boot.
676