PEL: Create trace wrapper for peltool
In preparation for peltool being compiled for non-BMC platforms where
libphosphor_logging.so isn't available, create a wrapper function for
tracing so phosphor::logging::log() isn't directly used by the code that
is part of peltool.
For now, the wrapper will just call phosphor::logging::log, but in the
future will be changed to call std::cerr when not on the BMC.
A few files were changed to make use of the new calls. Others will be
done with future commits. Only the code that is built into peltool
needs to use this. This mostly consists of the PEL section classes.
Using this new API does mean no extra data can be stored in the journal
metadata, as the systemd journal may not be available on some platforms
the tool may need to run on, such as AIX. Instead, the data can just be
added into the trace string itself.
In a future commit, the meson.build file will be refactored to remove
the libphosphor_logging dependency so the build will fail if a call to
the phosphor-logging's log() is made within peltool code.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I5e6c235d60466b031e15b157860c07a3f8ddb148
diff --git a/extensions/openpower-pels/private_header.cpp b/extensions/openpower-pels/private_header.cpp
index 31e0f61..74d895c 100644
--- a/extensions/openpower-pels/private_header.cpp
+++ b/extensions/openpower-pels/private_header.cpp
@@ -19,8 +19,9 @@
#include "log_id.hpp"
#include "pel_types.hpp"
#include "pel_values.hpp"
+#include "trace.hpp"
-#include <phosphor-logging/log.hpp>
+#include <fmt/format.h>
namespace openpower
{
@@ -28,7 +29,6 @@
{
namespace pv = openpower::pels::pel_values;
-using namespace phosphor::logging;
PrivateHeader::PrivateHeader(uint16_t componentID, uint32_t obmcLogID,
uint64_t timestamp)
@@ -77,8 +77,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Cannot unflatten private header",
- entry("ERROR=%s", e.what()));
+ trace::error(
+ fmt::format("Cannot unflatten private header: {}", e.what()));
_valid = false;
}
}
@@ -126,22 +126,22 @@
if (header().id != static_cast<uint16_t>(SectionID::privateHeader))
{
- log<level::ERR>("Invalid private header section ID",
- entry("ID=0x%X", header().id));
+ trace::error(fmt::format("Invalid private header section ID: {:#X}",
+ header().id));
failed = true;
}
if (header().version != privateHeaderVersion)
{
- log<level::ERR>("Invalid private header version",
- entry("VERSION=0x%X", header().version));
+ trace::error(fmt::format("Invalid private header version: {}",
+ header().version));
failed = true;
}
if (_sectionCount < minSectionCount)
{
- log<level::ERR>("Invalid section count in private header",
- entry("SECTION_COUNT=0x%X", _sectionCount));
+ trace::error(fmt::format("Invalid section count in private header: {}",
+ _sectionCount));
failed = true;
}