Update occ-control to use lg2 for all logging
Convert existing log<level>() trace statements to lg2::level()
Testing: Verified on Rainier - captured journal traces before and after
commit during boots, mode, pcap and ips changes.
Change-Id: I318fa7bf3902c641b0c28b09190db4b61d0a2fa9
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/app.cpp b/app.cpp
index 18453bb..291d9cf 100644
--- a/app.cpp
+++ b/app.cpp
@@ -9,13 +9,9 @@
#endif
#include <org/open_power/OCC/Device/error.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-using namespace phosphor::logging;
-
using namespace sdbusplus::org::open_power::OCC::Device::Error;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -29,7 +25,7 @@
auto r = sd_event_default(&event);
if (r < 0)
{
- log<level::ERR>("Error creating a default sd_event handler");
+ lg2::error("Error creating a default sd_event handler");
return r;
}
open_power::occ::EventPtr eventP{event};
diff --git a/occ_command.cpp b/occ_command.cpp
index 0b9faa1..30d8424 100644
--- a/occ_command.cpp
+++ b/occ_command.cpp
@@ -7,13 +7,10 @@
#include <unistd.h>
#include <org/open_power/OCC/Device/error.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
#include <format>
-#include <memory>
#include <string>
// #define TRACE_PACKETS
@@ -23,8 +20,6 @@
namespace occ
{
-using namespace phosphor::logging;
-
// Trace block of data in hex
void dump_hex(const std::vector<std::uint8_t>& data,
const unsigned int data_len)
@@ -50,7 +45,7 @@
if ((i % 16 == 15) || (i == (dump_length - 1)))
{
- log<level::INFO>(s.c_str());
+ lg2::info("{STRING}", "STRING", s);
s.clear();
}
}
@@ -65,32 +60,27 @@
std::bind(std::mem_fn(&OccCommand::activeStatusEvent), this,
std::placeholders::_1))
{
- log<level::DEBUG>(
- std::format("OccCommand::OccCommand(path={}, devicePath={}", this->path,
- devicePath)
- .c_str());
+ lg2::debug("OccCommand::OccCommand(path={PATH}, devicePath={DEVICE}",
+ "PATH", this->path, "DEVICE", devicePath);
}
void OccCommand::openDevice()
{
using namespace sdbusplus::org::open_power::OCC::Device::Error;
- log<level::DEBUG>(
- std::format("OccCommand::openDevice: calling open {}", devicePath)
- .c_str());
+ lg2::debug("OccCommand::openDevice: calling open {PATH}", "PATH",
+ devicePath);
fd = open(devicePath.c_str(), O_RDWR | O_NONBLOCK);
if (fd < 0)
{
const int openErrno = errno;
- log<level::ERR>(
- std::format(
- "OccCommand::openDevice: open failed (errno={}, path={})",
- openErrno, devicePath)
- .c_str());
+ lg2::error(
+ "OccCommand::openDevice: open failed (errno={ERR}, path={PATH})",
+ "ERR", openErrno, "PATH", devicePath);
}
else
{
- log<level::DEBUG>("OccCommand::openDevice: open success");
+ lg2::debug("OccCommand::openDevice: open success");
}
return;
@@ -100,7 +90,7 @@
{
if (fd >= 0)
{
- log<level::DEBUG>("OccCommand::closeDevice: calling close()");
+ lg2::debug("OccCommand::closeDevice: calling close()");
close(fd);
fd = -1;
}
@@ -114,7 +104,7 @@
response.clear();
- log<level::DEBUG>("OccCommand::send: calling openDevice()");
+ lg2::debug("OccCommand::send: calling openDevice()");
openDevice();
if (fd < 0)
@@ -125,13 +115,12 @@
const uint8_t cmd_type = command[0];
#ifdef TRACE_PACKETS
- log<level::INFO>(
- std::format("OCC{}: Sending 0x{:02X} command (length={}, {})",
- occInstance, cmd_type, command.size(), devicePath)
- .c_str());
+ lg2::info("OCC{INST}: Sending {CMD} command (length={LEN}, {PATH})", "INST",
+ occInstance, "CMD", lg2::hex, cmd_type, "LEN", command.size(),
+ "PATH", devicePath);
dump_hex(command);
#else
- log<level::DEBUG>("OccCommand::send: calling write()");
+ lg2::debug("OccCommand::send: calling write()");
#endif
int retries = 1; // Allow a retry if a command fails to get valid response
@@ -141,18 +130,17 @@
const int writeErrno = errno;
if ((rc < 0) || (rc != (int)command.size()))
{
- log<level::ERR>(
- std::format(
- "OccCommand::send: write(OCC{}, command:0x{:02X}) failed with errno={} (retries={})",
- occInstance, cmd_type, writeErrno, retries)
- .c_str());
+ lg2::error(
+ "OccCommand::send: write(OCC{INST}, command:{CMD}) failed with errno={ERR} (retries={RETRIES})",
+ "INST", occInstance, "CMD", lg2::hex, cmd_type, "ERR",
+ writeErrno, "RETRIES", retries);
status = CmdStatus::COMM_FAILURE;
// retry if available
continue;
}
else
{
- log<level::DEBUG>("OccCommand::send: write succeeded");
+ lg2::debug("OccCommand::send: write succeeded");
}
// Now read the response. This would be the content of occ-sram
@@ -173,19 +161,17 @@
}
else if (len == 0)
{
- log<level::DEBUG>("OccCommand::send: read completed");
+ lg2::debug("OccCommand::send: read completed");
// We have read all that we can.
status = CmdStatus::SUCCESS;
break;
}
else
{
- log<level::ERR>(
- std::format(
- "OccCommand::send: read(OCC{}, command:0x{:02X}) failed with errno={} (rspSize={}, retries={})",
- occInstance, cmd_type, readErrno, response.size(),
- retries)
- .c_str());
+ lg2::error(
+ "OccCommand::send: read(OCC{INST}, command:{CMD) failed with errno={ERR} (rspSize={LEN}, retries={RETRIES})",
+ "INST", occInstance, "CMD", lg2::hex, cmd_type, "ERR",
+ readErrno, "LEN", response.size(), "RETRIES", retries);
status = CmdStatus::COMM_FAILURE;
break;
}
@@ -199,11 +185,10 @@
if (response.size() > 2)
{
#ifdef TRACE_PACKETS
- log<level::INFO>(
- std::format(
- "OCC{}: Received 0x{:02X} response (length={} w/checksum)",
- occInstance, cmd_type, response.size())
- .c_str());
+ lg2::info(
+ "OCC{INST}: Received {CMD} response (length={LEN} w/checksum)",
+ "INST", occInstance, "CMD", lg2::hex, cmd_type, "LEN",
+ response.size());
dump_hex(response, 64);
#endif
@@ -219,11 +204,10 @@
}
if (calcChecksum != rspChecksum)
{
- log<level::ERR>(
- std::format("OCC{}: Checksum Mismatch: response "
- "0x{:04X}, calculated 0x{:04X}",
- occInstance, rspChecksum, calcChecksum)
- .c_str());
+ lg2::error("OCC{INST}: Checksum Mismatch: response "
+ "{RCVD}, calculated {EXPECT}",
+ "INST", occInstance, "RCVD", rspChecksum, "EXPECT",
+ calcChecksum);
dump_hex(response);
status = CmdStatus::COMM_FAILURE;
}
@@ -241,31 +225,27 @@
}
else
{
- log<level::ERR>(
- std::format(
- "OccCommand::send: Response command mismatch "
- "(sent: "
- "0x{:02X}, rsp: 0x{:02X}, rsp seq#: 0x{:02X}",
- command[0], response[1], response[0])
- .c_str());
+ lg2::error("OccCommand::send: Response command mismatch "
+ "(sent: "
+ "{CMD}, rsp: {STATUS}, rsp seq#: {SEQ}",
+ "CMD", lg2::hex, command[0], "STATUS", lg2::hex,
+ response[1], "SEQ", lg2::hex, response[0]);
dump_hex(response, 64);
}
}
}
else
{
- log<level::ERR>(
- std::format(
- "OccCommand::send: Invalid OCC{} response length: {}",
- occInstance, response.size())
- .c_str());
+ lg2::error(
+ "OccCommand::send: Invalid OCC{INST} response length: {LEN}",
+ "INST", occInstance, "LEN", response.size());
status = CmdStatus::FAILURE;
dump_hex(response);
}
if (retries > 0)
{
- log<level::ERR>("OccCommand::send: Command will be retried");
+ lg2::error("OccCommand::send: Command will be retried");
response.clear();
}
} while (retries-- > 0);
diff --git a/occ_command.hpp b/occ_command.hpp
index 2adf573..bbebe06 100644
--- a/occ_command.hpp
+++ b/occ_command.hpp
@@ -80,7 +80,7 @@
COMM_FAILURE = 0x03
};
-/** @brief Trace block of data in hex with log<level:INFO>
+/** @brief Trace block of data in hex with lg2:info()
*
* @param[in] data - vector containing data to trace
* @param[in] data_len - optional number of bytes to trace
diff --git a/occ_dbus.cpp b/occ_dbus.cpp
index 96d4554..e018246 100644
--- a/occ_dbus.cpp
+++ b/occ_dbus.cpp
@@ -2,9 +2,8 @@
#include "utils.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
-#include <format>
#include <iostream>
namespace open_power
@@ -14,7 +13,6 @@
namespace dbus
{
-using namespace phosphor::logging;
using namespace std::string_literals;
const auto defaultChassisPath =
"/xyz/openbmc_project/inventory/system/chassis"s;
@@ -120,7 +118,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("set Unit propety failed", entry("ERROR=%s", e.what()));
+ lg2::error("set Unit propety failed: error={ERR}", "ERR", e.what());
return false;
}
@@ -137,8 +135,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("get Unit propety failed",
- entry("ERROR=%s", e.what()));
+ lg2::error("get Unit propety failed: error={ERR}", "ERR", e.what());
}
}
@@ -217,11 +214,8 @@
else if (std::find(paths.begin(), paths.end(), defaultChassisPath) ==
paths.end())
{
- log<level::ERR>(
- std::format(
- "Could not find a chassis out of {} chassis objects",
- paths.size())
- .c_str());
+ lg2::error("Could not find a chassis out of {NUM} chassis objects",
+ "NUM", paths.size());
// Can't throw an exception here, the sdeventplus timer
// just catches it.
abort();
@@ -229,9 +223,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("Error looking up chassis objects: {}", e.what())
- .c_str());
+ lg2::error("Error looking up chassis objects: {ERR}", "ERR", e.what());
abort();
}
diff --git a/occ_device.cpp b/occ_device.cpp
index ded5db9..98eeab7 100644
--- a/occ_device.cpp
+++ b/occ_device.cpp
@@ -3,7 +3,7 @@
#include "occ_manager.hpp"
#include "occ_status.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <filesystem>
#include <iostream>
@@ -13,8 +13,6 @@
namespace occ
{
-using namespace phosphor::logging;
-
void Device::setActive(bool active)
{
std::string data = active ? "1" : "0";
@@ -25,9 +23,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(std::format("Failed to set {} active: {}",
- devPath.c_str(), e.what())
- .c_str());
+ lg2::error("Failed to set {DEVICE} active: {ERROR}", "DEVICE", devPath,
+ "ERROR", e.what());
}
}
@@ -151,10 +148,8 @@
}
catch (const fs::filesystem_error& e)
{
- log<level::ERR>(
- std::format("getFilenameByRegex: Failed to get filename: {}",
- e.what())
- .c_str());
+ lg2::error("getFilenameByRegex: Failed to get filename: {ERROR}",
+ "ERROR", e.what());
}
// Return empty path
diff --git a/occ_errors.cpp b/occ_errors.cpp
index bfff111..c764c6f 100644
--- a/occ_errors.cpp
+++ b/occ_errors.cpp
@@ -8,10 +8,10 @@
#include <org/open_power/OCC/Device/error.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-#include <format>
namespace open_power
{
namespace occ
@@ -31,10 +31,8 @@
const int open_errno = errno;
if (fd < 0)
{
- log<level::ERR>(
- std::format("Error::openFile: open of {} failed (errno={})",
- file.c_str(), open_errno)
- .c_str());
+ lg2::error("Error::openFile: open of {FILE} failed (errno={ERR})",
+ "FILE", file.c_str(), "ERR", open_errno);
elog<OpenFailure>(phosphor::logging::org::open_power::OCC::Device::
OpenFailure::CALLOUT_ERRNO(open_errno),
phosphor::logging::org::open_power::OCC::Device::
@@ -52,8 +50,8 @@
if (r < 0)
{
- log<level::ERR>("Failed to register callback handler",
- entry("ERROR=%s", strerror(-r)));
+ lg2::error("Failed to register callback handler: error={ERR}", "ERR",
+ strerror(-r));
elog<InternalFailure>();
}
}
@@ -172,7 +170,7 @@
auto r = lseek(fd, 0, SEEK_SET);
if (r < 0)
{
- log<level::ERR>("Failure seeking error file to START");
+ lg2::error("Failure seeking error file to START");
elog<ConfigFailure>(
phosphor::logging::org::open_power::OCC::Device::ConfigFailure::
CALLOUT_ERRNO(errno),
diff --git a/occ_ffdc.cpp b/occ_ffdc.cpp
index da3df79..763660f 100644
--- a/occ_ffdc.cpp
+++ b/occ_ffdc.cpp
@@ -12,12 +12,11 @@
#include <org/open_power/OCC/Device/error.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Logging/Create/server.hpp>
-#include <format>
-
namespace open_power
{
namespace occ
@@ -43,10 +42,8 @@
uint8_t, uint8_t, sdbusplus::message::unix_fd>>
pelFFDCInfo;
- log<level::INFO>(
- std::format("Creating PEL for OCC{} with SBE FFDC: {} - SRC6: 0x{:08X}",
- src6 >> 16, path, src6)
- .c_str());
+ lg2::info("Creating PEL for OCC{INST} with SBE FFDC: {PATH} - SRC6: {SRC}",
+ "INST", src6 >> 16, "PATH", path, "SRC", lg2::hex, src6);
if (fd > 0)
{
@@ -92,8 +89,7 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Failed to create PEL: {}", e.what()).c_str());
+ lg2::error("Failed to create PEL: {ERR}", "ERR", e.what());
}
return plid;
@@ -118,9 +114,8 @@
additionalData.emplace("OCC", std::to_string(instance));
- log<level::INFO>(
- std::format("Creating OCC Reset PEL for OCC{}: {}", instance, path)
- .c_str());
+ lg2::info("Creating OCC Reset PEL for OCC{INST}: {PATH}", "INST", instance,
+ "PATH", path);
auto& bus = utils::getBus();
@@ -150,9 +145,7 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Failed to create OCC Reset PEL: {}", e.what())
- .c_str());
+ lg2::error("Failed to create OCC Reset PEL: {ERR}", "ERR", e.what());
}
}
@@ -200,7 +193,7 @@
tfd = mkostemp(templateString.data(), O_RDWR);
if (tfd < 0)
{
- log<level::ERR>("Couldn't create temporary FFDC file");
+ lg2::error("Couldn't create temporary FFDC file");
}
else
{
@@ -215,7 +208,7 @@
fs::remove(temporaryFiles.back().first);
temporaryFiles.pop_back();
tfd = -1;
- log<level::ERR>("Couldn't write temporary FFDC file");
+ lg2::error("Couldn't write temporary FFDC file");
break;
}
if (!r)
@@ -238,20 +231,15 @@
auto journalFile = makeJsonFFDCFile(getJournalEntries(lines, executable));
if (journalFile && journalFile->fd() != -1)
{
- log<level::DEBUG>(
- std::format(
- "addJournalEntries: Added up to {} journal entries for {}",
- lines, executable)
- .c_str());
+ lg2::debug(
+ "addJournalEntries: Added up to {NUM} journal entries for {APP}",
+ "NUM", lines, "APP", executable);
fileList.emplace_back(FFDCFormat::JSON, 0x01, 0x01, journalFile->fd());
}
else
{
- log<level::ERR>(
- std::format(
- "addJournalEntries: Failed to add journal entries for {}",
- executable)
- .c_str());
+ lg2::error("addJournalEntries: Failed to add journal entries for {APP}",
+ "APP", executable);
}
return journalFile;
}
@@ -274,20 +262,16 @@
else
{
auto e = errno;
- log<level::ERR>(
- std::format(
- "makeJsonFFDCFile: Failed call to write JSON FFDC file, errno={}",
- e)
- .c_str());
+ lg2::error(
+ "makeJsonFFDCFile: Failed call to write JSON FFDC file, errno={ERR}",
+ "ERR", e);
}
}
else
{
auto e = errno;
- log<level::ERR>(
- std::format("makeJsonFFDCFile: Failed called to mkostemp, errno={}",
- e)
- .c_str());
+ lg2::error("makeJsonFFDCFile: Failed called to mkostemp, errno={ERR}",
+ "ERR", e);
}
return nullptr;
}
@@ -428,10 +412,8 @@
if (_fd() == -1)
{
auto e = errno;
- log<level::ERR>(
- std::format("FFDCFile: Could not open FFDC file {}. errno {}",
- _name.string(), e)
- .c_str());
+ lg2::error("FFDCFile: Could not open FFDC file {FILE}. errno {ERR}",
+ "FILE", _name.string(), "ERR", e);
}
}
diff --git a/occ_manager.cpp b/occ_manager.cpp
index 7823111..62a2b38 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -8,7 +8,7 @@
#include "utils.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <chrono>
@@ -97,11 +97,9 @@
// a chance to settle.
prevOCCSearch = occs;
- log<level::INFO>(
- std::format(
- "Manager::findAndCreateObjects(): Waiting for OCCs (currently {})",
- occs.size())
- .c_str());
+ lg2::info(
+ "Manager::findAndCreateObjects(): Waiting for OCCs (currently {QTY})",
+ "QTY", occs.size());
discoverTimer->restartOnce(10s);
}
@@ -112,11 +110,9 @@
// createObjects requires OCC0 first.
std::sort(occs.begin(), occs.end());
- log<level::INFO>(
- std::format(
- "Manager::findAndCreateObjects(): Creating {} OCC Status Objects",
- occs.size())
- .c_str());
+ lg2::info(
+ "Manager::findAndCreateObjects(): Creating {QTY} OCC Status Objects",
+ "QTY", occs.size());
for (auto id : occs)
{
createObjects(std::string(OCC_NAME) + std::to_string(id));
@@ -139,7 +135,7 @@
{
if (tracedHostWait)
{
- log<level::INFO>(
+ lg2::info(
"Manager::findAndCreateObjects(): Host is running");
tracedHostWait = false;
}
@@ -149,7 +145,7 @@
{
if (!tracedHostWait)
{
- log<level::INFO>(
+ lg2::info(
"Manager::findAndCreateObjects(): Waiting for host to start");
tracedHostWait = true;
}
@@ -159,8 +155,7 @@
{
// Host is no longer running, disable throttle timer and
// make sure traces are not throttled
- log<level::INFO>(
- "findAndCreateObjects(): disabling sensor timer");
+ lg2::info("findAndCreateObjects(): disabling sensor timer");
throttlePldmTraceTimer->setEnabled(false);
pldmHandle->setTraceThrottle(false);
}
@@ -170,11 +165,9 @@
}
else
{
- log<level::INFO>(
- std::format(
- "Manager::findAndCreateObjects(): Waiting for {} to complete...",
- HOST_ON_FILE)
- .c_str());
+ lg2::info(
+ "Manager::findAndCreateObjects(): Waiting for {FILE} to complete...",
+ "FILE", HOST_ON_FILE);
discoverTimer->restartOnce(10s);
}
#endif
@@ -193,7 +186,7 @@
if (waitingForHost)
{
waitingForHost = false;
- log<level::INFO>("checkAllActiveSensors(): Host is now running");
+ lg2::info("checkAllActiveSensors(): Host is now running");
}
// Start with the assumption that all are available
@@ -208,11 +201,9 @@
if (match != queuedActiveState.end())
{
queuedActiveState.erase(match);
- log<level::INFO>(
- std::format(
- "checkAllActiveSensors(): OCC{} is ACTIVE (queued)",
- instance)
- .c_str());
+ lg2::info(
+ "checkAllActiveSensors(): OCC{INST} is ACTIVE (queued)",
+ "INST", instance);
obj->occActive(true);
}
else
@@ -220,11 +211,9 @@
allActiveSensorAvailable = false;
if (!tracedSensorWait)
{
- log<level::INFO>(
- std::format(
- "checkAllActiveSensors(): Waiting on OCC{} Active sensor",
- instance)
- .c_str());
+ lg2::info(
+ "checkAllActiveSensors(): Waiting on OCC{INST} Active sensor",
+ "INST", instance);
tracedSensorWait = true;
#ifdef PLDM
// Make sure PLDM traces are not throttled
@@ -252,15 +241,13 @@
if (!waitingForHost)
{
waitingForHost = true;
- log<level::INFO>(
- "checkAllActiveSensors(): Waiting for host to start");
+ lg2::info("checkAllActiveSensors(): Waiting for host to start");
#ifdef PLDM
if (throttlePldmTraceTimer->isEnabled())
{
// Host is no longer running, disable throttle timer and
// make sure traces are not throttled
- log<level::INFO>(
- "checkAllActiveSensors(): disabling sensor timer");
+ lg2::info("checkAllActiveSensors(): disabling sensor timer");
throttlePldmTraceTimer->setEnabled(false);
pldmHandle->setTraceThrottle(false);
}
@@ -285,7 +272,7 @@
#endif
if (waitingForAllOccActiveSensors)
{
- log<level::INFO>(
+ lg2::info(
"checkAllActiveSensors(): OCC Active sensors are available");
waitingForAllOccActiveSensors = false;
@@ -295,7 +282,7 @@
if (!waitForAllOccsTimer->isEnabled())
{
- log<level::WARNING>(
+ lg2::warning(
"occsNotAllRunning: Restarting waitForAllOccTimer");
// restart occ wait timer to check status after reset
// completes
@@ -311,7 +298,7 @@
// Not all sensors were available, so keep waiting
if (!tracedSensorWait)
{
- log<level::INFO>(
+ lg2::info(
"checkAllActiveSensors(): Waiting for OCC Active sensors to become available");
tracedSensorWait = true;
}
@@ -387,10 +374,8 @@
if (statusObjects.back()->isMasterOcc())
{
- log<level::INFO>(
- std::format("Manager::createObjects(): OCC{} is the master",
- statusObjects.back()->getOccInstanceID())
- .c_str());
+ lg2::info("Manager::createObjects(): OCC{INST} is the master", "INST",
+ statusObjects.back()->getOccInstanceID());
_pollTimer->setEnabled(false);
#ifdef POWER10
@@ -416,19 +401,15 @@
{
resetRequired = true;
resetInstance = instance;
- log<level::ERR>(
- std::format(
- "resetOccRequest: PM Complex reset was requested due to OCC{}",
- instance)
- .c_str());
+ lg2::error(
+ "resetOccRequest: PM Complex reset was requested due to OCC{INST}",
+ "INST", instance);
}
else if (instance != resetInstance)
{
- log<level::WARNING>(
- std::format(
- "resetOccRequest: Ignoring PM Complex reset request for OCC{}, because reset already outstanding for OCC{}",
- instance, resetInstance)
- .c_str());
+ lg2::warning(
+ "resetOccRequest: Ignoring PM Complex reset request for OCC{INST}, because reset already outstanding for OCC{RINST}",
+ "INST", instance, "RINST", resetInstance);
}
}
@@ -439,11 +420,9 @@
{
resetInProgress = true;
resetInstance = instance;
- log<level::ERR>(
- std::format(
- "initiateOccRequest: Initiating PM Complex reset due to OCC{}",
- instance)
- .c_str());
+ lg2::error(
+ "initiateOccRequest: Initiating PM Complex reset due to OCC{INST}",
+ "INST", instance);
#ifdef PLDM
pldmHandle->resetOCC(instance);
#endif
@@ -451,11 +430,9 @@
}
else
{
- log<level::WARNING>(
- std::format(
- "initiateOccRequest: Ignoring PM Complex reset request for OCC{}, because reset already in process for OCC{}",
- instance, resetInstance)
- .c_str());
+ lg2::warning(
+ "initiateOccRequest: Ignoring PM Complex reset request for OCC{INST}, because reset already in process for OCC{RINST}",
+ "INST", instance, "RINST", resetInstance);
}
}
@@ -465,11 +442,9 @@
{
if (resetInProgress)
{
- log<level::INFO>(
- std::format(
- "statusCallBack: Ignoring OCC{} activate because a reset has been initiated due to OCC{}",
- instance, resetInstance)
- .c_str());
+ lg2::info(
+ "statusCallBack: Ignoring OCC{INST} activate because a reset has been initiated due to OCC{INST}",
+ "INST", instance, "RINST", resetInstance);
return;
}
@@ -501,7 +476,7 @@
if (!waitForAllOccsTimer->isEnabled())
{
- log<level::WARNING>(
+ lg2::warning(
"occsNotAllRunning: Restarting waitForAllOccTimer");
// restart occ wait timer
waitForAllOccsTimer->restartOnce(60s);
@@ -521,10 +496,8 @@
// Start poll timer if not already started
if (!_pollTimer->isEnabled())
{
- log<level::INFO>(
- std::format("Manager: OCCs will be polled every {} seconds",
- pollInterval)
- .c_str());
+ lg2::info("Manager: OCCs will be polled every {TIME} seconds",
+ "TIME", pollInterval);
// Send poll and start OCC poll timer
pollerTimerExpired();
@@ -539,10 +512,8 @@
}
else
{
- log<level::INFO>(
- std::format("OCC{} disabled, but currently no active OCCs",
- instance)
- .c_str());
+ lg2::info("OCC{INST} disabled, but currently no active OCCs",
+ "INST", instance);
}
if (activeCount == 0)
@@ -553,11 +524,9 @@
{
// All OCC active sensors are clear (reset should be in
// progress)
- log<level::INFO>(
- std::format(
- "statusCallBack: Clearing resetInProgress (activeCount={}, OCC{}, status={})",
- activeCount, instance, status)
- .c_str());
+ lg2::info(
+ "statusCallBack: Clearing resetInProgress (activeCount={COUNT}, OCC{INST}, status={STATUS})",
+ "COUNT", activeCount, "INST", instance, "STATUS", status);
resetInProgress = false;
resetInstance = 255;
}
@@ -565,7 +534,7 @@
// Stop OCC poll timer
if (_pollTimer->isEnabled())
{
- log<level::INFO>(
+ lg2::info(
"Manager::statusCallBack(): OCCs are not running, stopping poll timer");
_pollTimer->setEnabled(false);
}
@@ -580,11 +549,9 @@
}
else if (resetInProgress)
{
- log<level::INFO>(
- std::format(
- "statusCallBack: Skipping clear of resetInProgress (activeCount={}, OCC{}, status={})",
- activeCount, instance, status)
- .c_str());
+ lg2::info(
+ "statusCallBack: Skipping clear of resetInProgress (activeCount={COUNT}, OCC{INST}, status={STATUS})",
+ "COUNT", activeCount, "INST", instance, "STATUS", status);
}
#ifdef READ_OCC_SENSORS
// Clear OCC sensors
@@ -640,9 +607,8 @@
if (obj != statusObjects.end() && (*obj)->occActive())
{
- log<level::INFO>(
- std::format("SBE timeout, requesting HRESET (OCC{})", instance)
- .c_str());
+ lg2::info("SBE timeout, requesting HRESET (OCC{INST})", "INST",
+ instance);
setSBEState(instance, SBE_STATE_NOT_USABLE);
@@ -662,15 +628,13 @@
{
if (!hostRunning && (status == true))
{
- log<level::WARNING>(
- std::format(
- "updateOCCActive: Host is not running yet (OCC{} active={}), clearing sensor received",
- instance, status)
- .c_str());
+ lg2::warning(
+ "updateOCCActive: Host is not running yet (OCC{INST} active={STAT}), clearing sensor received",
+ "INST", instance, "STAT", status);
(*obj)->setPldmSensorReceived(false);
if (!waitingForAllOccActiveSensors)
{
- log<level::INFO>(
+ lg2::info(
"updateOCCActive: Waiting for Host and all OCC Active Sensors");
waitingForAllOccActiveSensors = true;
}
@@ -689,21 +653,17 @@
{
if (hostRunning)
{
- log<level::WARNING>(
- std::format(
- "updateOCCActive: No status object to update for OCC{} (active={})",
- instance, status)
- .c_str());
+ lg2::warning(
+ "updateOCCActive: No status object to update for OCC{INST} (active={STAT})",
+ "INST", instance, "STAT", status);
}
else
{
if (status == true)
{
- log<level::WARNING>(
- std::format(
- "updateOCCActive: No status objects and Host is not running yet (OCC{} active={})",
- instance, status)
- .c_str());
+ lg2::warning(
+ "updateOCCActive: No status objects and Host is not running yet (OCC{INST} active={STAT})",
+ "INST", instance, "STAT", status);
}
}
if (status == true)
@@ -741,8 +701,7 @@
{
if (success)
{
- log<level::INFO>(
- std::format("HRESET succeeded (OCC{})", instance).c_str());
+ lg2::info("HRESET succeeded (OCC{INST})", "INST", instance);
setSBEState(instance, SBE_STATE_BOOTED);
@@ -753,9 +712,8 @@
if (sbeCanDump(instance))
{
- log<level::INFO>(
- std::format("HRESET failed (OCC{}), triggering SBE dump", instance)
- .c_str());
+ lg2::info("HRESET failed (OCC{INST}), triggering SBE dump", "INST",
+ instance);
auto& bus = utils::getBus();
uint32_t src6 = instance << 16;
@@ -793,17 +751,17 @@
"xyz.openbmc_project.Dump.Create.Error.Disabled";
if (e.name() == ERROR_DUMP_DISABLED)
{
- log<level::INFO>("Dump is disabled, skipping");
+ lg2::info("Dump is disabled, skipping");
}
else
{
- log<level::ERR>("Dump failed");
+ lg2::error("Dump failed");
}
}
}
// SBE Reset failed, try PM Complex reset
- log<level::ERR>("sbeHRESETResult: Forcing PM Complex reset");
+ lg2::error("sbeHRESETResult: Forcing PM Complex reset");
resetOccRequest(instance);
}
@@ -831,7 +789,7 @@
}
catch (openpower::phal::exception::SbeError& e)
{
- log<level::INFO>("Failed to query SBE state");
+ lg2::info("Failed to query SBE state");
}
// allow the dump in the error case
@@ -853,8 +811,7 @@
}
catch (const openpower::phal::exception::SbeError& e)
{
- log<level::ERR>(
- std::format("Failed to set SBE state: {}", e.what()).c_str());
+ lg2::error("Failed to set SBE state: {ERROR}", "ERROR", e.what());
}
}
@@ -869,7 +826,7 @@
}
catch (const openpower::phal::exception::PdbgError& e)
{
- log<level::ERR>("pdbg initialization failed");
+ lg2::error("pdbg initialization failed");
return nullptr;
}
}
@@ -883,7 +840,7 @@
}
}
- log<level::ERR>("Failed to get pdbg target");
+ lg2::error("Failed to get pdbg target");
return nullptr;
}
#endif
@@ -892,20 +849,19 @@
{
if (!_pollTimer)
{
- log<level::ERR>("pollerTimerExpired() ERROR: Timer not defined");
+ lg2::error("pollerTimerExpired() ERROR: Timer not defined");
return;
}
#ifdef POWER10
if (resetRequired)
{
- log<level::ERR>("pollerTimerExpired() - Initiating PM Complex reset");
+ lg2::error("pollerTimerExpired() - Initiating PM Complex reset");
initiateOccRequest(resetInstance);
if (!waitForAllOccsTimer->isEnabled())
{
- log<level::WARNING>(
- "pollerTimerExpired: Restarting waitForAllOccTimer");
+ lg2::warning("pollerTimerExpired: Restarting waitForAllOccTimer");
// restart occ wait timer
waitForAllOccsTimer->restartOnce(60s);
}
@@ -942,10 +898,8 @@
else
{
// No OCCs running, so poll timer will not be restarted
- log<level::INFO>(
- std::format(
- "Manager::pollerTimerExpired: poll timer will not be restarted")
- .c_str());
+ lg2::info(
+ "Manager::pollerTimerExpired: poll timer will not be restarted");
}
}
@@ -974,10 +928,9 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format("readTempSensors: Failed reading {}, errno = {}",
- file.path().string(), e.code().value())
- .c_str());
+ lg2::debug(
+ "readTempSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", file.path().string(), "ERROR", e.code().value());
continue;
}
@@ -992,10 +945,10 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format("readTempSensors: Failed reading {}, errno = {}",
- filePathString + fruTypeSuffix, e.code().value())
- .c_str());
+ lg2::debug(
+ "readTempSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", filePathString + fruTypeSuffix, "ERROR",
+ e.code().value());
continue;
}
@@ -1032,11 +985,9 @@
auto iter = dimmTempSensorName.find(fruTypeValue);
if (iter == dimmTempSensorName.end())
{
- log<level::ERR>(
- std::format(
- "readTempSensors: Fru type error! fruTypeValue = {}) ",
- fruTypeValue)
- .c_str());
+ lg2::error(
+ "readTempSensors: Fru type error! fruTypeValue = {FRU}) ",
+ "FRU", fruTypeValue);
continue;
}
@@ -1087,11 +1038,10 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format(
- "readTempSensors: Failed reading {}, errno = {}",
- filePathString + maxSuffix, e.code().value())
- .c_str());
+ lg2::debug(
+ "readTempSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", filePathString + maxSuffix, "ERROR",
+ e.code().value());
}
}
@@ -1102,10 +1052,10 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format("readTempSensors: Failed reading {}, errno = {}",
- filePathString + faultSuffix, e.code().value())
- .c_str());
+ lg2::debug(
+ "readTempSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", filePathString + faultSuffix, "ERROR",
+ e.code().value());
continue;
}
@@ -1124,11 +1074,10 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format(
- "readTempSensors: Failed reading {}, errno = {}",
- filePathString + inputSuffix, e.code().value())
- .c_str());
+ lg2::debug(
+ "readTempSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", filePathString + inputSuffix, "ERROR",
+ e.code().value());
// if errno == EAGAIN(Resource temporarily unavailable) then set
// temp to 0, to avoid using old temp, and affecting FAN
@@ -1238,10 +1187,9 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format("readPowerSensors: Failed reading {}, errno = {}",
- file.path().string(), e.code().value())
- .c_str());
+ lg2::debug(
+ "readPowerSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", file.path().string(), "ERROR", e.code().value());
continue;
}
@@ -1272,10 +1220,10 @@
}
catch (const std::system_error& e)
{
- log<level::DEBUG>(
- std::format("readPowerSensors: Failed reading {}, errno = {}",
- filePathString + inputSuffix, e.code().value())
- .c_str());
+ lg2::debug(
+ "readPowerSensors: Failed reading {PATH}, errno = {ERROR}",
+ "PATH", filePathString + inputSuffix, "ERROR",
+ e.code().value());
continue;
}
@@ -1360,11 +1308,9 @@
{
if (!tracedError[id])
{
- log<level::ERR>(
- std::format(
- "Manager::getSensorValues: OCC{} sensor path missing: {}",
- id, sensorPath.c_str())
- .c_str());
+ lg2::error(
+ "Manager::getSensorValues: OCC{INST} sensor path missing: {PATH}",
+ "INST", id, "PATH", sensorPath);
tracedError[id] = true;
}
}
@@ -1395,9 +1341,8 @@
// Round to nearest meter
altitude = uint16_t(sensorVal + 0.5);
}
- log<level::DEBUG>(std::format("readAltitude: sensor={} ({}m)",
- sensorVal, altitude)
- .c_str());
+ lg2::debug("readAltitude: sensor={VALUE} ({ALT}m)", "VALUE",
+ sensorVal, "ALT", altitude);
traceAltitudeErr = true;
}
else
@@ -1405,9 +1350,7 @@
if (traceAltitudeErr)
{
traceAltitudeErr = false;
- log<level::DEBUG>(
- std::format("Invalid altitude value: {}", sensorVal)
- .c_str());
+ lg2::debug("Invalid altitude value: {ALT}", "ALT", sensorVal);
}
}
}
@@ -1416,8 +1359,7 @@
if (traceAltitudeErr)
{
traceAltitudeErr = false;
- log<level::INFO>(
- std::format("Unable to read Altitude: {}", e.what()).c_str());
+ lg2::info("Unable to read Altitude: {ERROR}", "ERROR", e.what());
}
altitude = 0xFFFF; // not available
}
@@ -1435,7 +1377,7 @@
auto valPropMap = msgData.find(AMBIENT_PROP);
if (valPropMap == msgData.end())
{
- log<level::DEBUG>("ambientCallback: Unknown ambient property changed");
+ lg2::debug("ambientCallback: Unknown ambient property changed");
return;
}
currentTemp = std::get<double>(valPropMap->second);
@@ -1459,10 +1401,8 @@
// If ambient changes, notify OCCs
if (truncatedTemp != ambient)
{
- log<level::DEBUG>(
- std::format("ambientCallback: Ambient change from {} to {}C",
- ambient, currentTemp)
- .c_str());
+ lg2::debug("ambientCallback: Ambient change from {OLD} to {NEW}C",
+ "OLD", ambient, "NEW", currentTemp);
ambient = truncatedTemp;
if (altitude == 0xFFFF)
@@ -1471,10 +1411,8 @@
readAltitude();
}
- log<level::DEBUG>(
- std::format("ambientCallback: Ambient: {}C, altitude: {}m", ambient,
- altitude)
- .c_str());
+ lg2::debug("ambientCallback: Ambient: {TEMP}C, altitude: {ALT}m",
+ "TEMP", ambient, "ALT", altitude);
#ifdef POWER10
// Send ambient and altitude to all OCCs
for (auto& obj : statusObjects)
@@ -1509,18 +1447,16 @@
{
if (resetInProgress)
{
- log<level::WARNING>(
+ lg2::warning(
"occsNotAllRunning: Ignoring waitForAllOccsTimer because reset is in progress");
return;
}
if (activeCount != statusObjects.size())
{
// Not all OCCs went active
- log<level::WARNING>(
- std::format(
- "occsNotAllRunning: Active OCC count ({}) does not match expected count ({})",
- activeCount, statusObjects.size())
- .c_str());
+ lg2::warning(
+ "occsNotAllRunning: Active OCC count ({COUNT}) does not match expected count ({EXP})",
+ "COUNT", activeCount, "EXP", statusObjects.size());
// Procs may be garded, so may be expected
}
@@ -1530,8 +1466,7 @@
if (!waitForAllOccsTimer->isEnabled())
{
- log<level::WARNING>(
- "occsNotAllRunning: Restarting waitForAllOccTimer");
+ lg2::warning("occsNotAllRunning: Restarting waitForAllOccTimer");
// restart occ wait timer
waitForAllOccsTimer->restartOnce(60s);
}
@@ -1561,7 +1496,7 @@
}
else
{
- log<level::ERR>(
+ lg2::error(
"throttlePldmTraceExpired(): OCC active sensors still not available!");
// Create PEL
createPldmSensorPEL();
@@ -1571,7 +1506,7 @@
{
// Make sure traces are not throttled
pldmHandle->setTraceThrottle(false);
- log<level::INFO>(
+ lg2::info(
"throttlePldmTraceExpired(): host it not running ignoring sensor timer");
}
}
@@ -1583,10 +1518,8 @@
additionalData.emplace("_PID", std::to_string(getpid()));
- log<level::INFO>(
- std::format(
- "createPldmSensorPEL(): Unable to find PLDM sensors for the OCCs")
- .c_str());
+ lg2::info(
+ "createPldmSensorPEL(): Unable to find PLDM sensors for the OCCs");
auto& bus = utils::getBus();
@@ -1617,10 +1550,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Failed to create MISSING_OCC_SENSORS PEL: {}",
- e.what())
- .c_str());
+ lg2::error("Failed to create MISSING_OCC_SENSORS PEL: {ERROR}", "ERROR",
+ e.what());
}
}
#endif // PLDM
@@ -1643,11 +1574,8 @@
if (match != queuedActiveState.end())
{
queuedActiveState.erase(match);
- log<level::INFO>(
- std::format(
- "validateOccMaster: OCC{} is ACTIVE (queued)",
- instance)
- .c_str());
+ lg2::info("validateOccMaster: OCC{INST} is ACTIVE (queued)",
+ "INST", instance);
obj->occActive(true);
}
else
@@ -1658,21 +1586,17 @@
#endif
if (obj->occActive())
{
- log<level::INFO>(
- std::format(
- "validateOccMaster: OCC{} is ACTIVE after reading sensor",
- instance)
- .c_str());
+ lg2::info(
+ "validateOccMaster: OCC{INST} is ACTIVE after reading sensor",
+ "INST", instance);
}
}
}
else
{
- log<level::WARNING>(
- std::format(
- "validateOccMaster: HOST is not running (OCC{})",
- instance)
- .c_str());
+ lg2::warning(
+ "validateOccMaster: HOST is not running (OCC{INST})",
+ "INST", instance);
return;
}
}
@@ -1688,11 +1612,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "validateOccMaster: Multiple OCC masters! ({} and {})",
- masterInstance, instance)
- .c_str());
+ lg2::error(
+ "validateOccMaster: Multiple OCC masters! ({MAST1} and {MAST2})",
+ "MAST1", masterInstance, "MAST2", instance);
// request reset
obj->deviceError(Error::Descriptor(PRESENCE_ERROR_PATH));
}
@@ -1701,20 +1623,16 @@
if (masterInstance < 0)
{
- log<level::ERR>(
- std::format("validateOccMaster: Master OCC not found! (of {} OCCs)",
- statusObjects.size())
- .c_str());
+ lg2::error("validateOccMaster: Master OCC not found! (of {NUM} OCCs)",
+ "NUM", statusObjects.size());
// request reset
statusObjects.front()->deviceError(
Error::Descriptor(PRESENCE_ERROR_PATH));
}
else
{
- log<level::INFO>(
- std::format("validateOccMaster: OCC{} is master of {} OCCs",
- masterInstance, activeCount)
- .c_str());
+ lg2::info("validateOccMaster: OCC{INST} is master of {COUNT} OCCs",
+ "INST", masterInstance, "COUNT", activeCount);
#ifdef POWER10
pmode->updateDbusSafeMode(false);
#endif
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp
index 8567784..61e9ad3 100644
--- a/occ_pass_through.cpp
+++ b/occ_pass_through.cpp
@@ -7,12 +7,9 @@
#include <unistd.h>
#include <org/open_power/OCC/Device/error.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
-#include <format>
#include <memory>
#include <string>
@@ -75,11 +72,9 @@
if (!occActive)
{
- log<level::ERR>(
- std::format(
- "PassThrough::send() - OCC{} not active, command not sent",
- occInstance)
- .c_str());
+ lg2::error(
+ "PassThrough::send() - OCC{INST} not active, command not sent",
+ "INST", occInstance);
return response;
}
@@ -101,42 +96,35 @@
dataString += "...";
}
}
- log<level::INFO>(
- std::format(
- "PassThrough::send() Sending 0x{:02X} command to OCC{} (data len={}, data={})",
- command.front(), occInstance, dataLen, dataString)
- .c_str());
+ lg2::info(
+ "PassThrough::send() Sending {CMD} command to OCC{INST} (data len={LEN}, data={DATA})",
+ "CMD", lg2::hex, command.front(), "INST", occInstance, "LEN",
+ dataLen, "DATA", dataString);
}
else
{
- log<level::INFO>(
- std::format("PassThrough::send() Sending 0x{:02X} command to OCC{}",
- command.front(), occInstance)
- .c_str());
+ lg2::info("PassThrough::send() Sending {CMD} command to OCC{INST}",
+ "CMD", command.front(), "INST", occInstance);
}
CmdStatus status = occCmd.send(command, response);
if (status == CmdStatus::SUCCESS)
{
if (response.size() >= 5)
{
- log<level::DEBUG>(
- std::format("PassThrough::send() response had {} bytes",
- response.size())
- .c_str());
+ lg2::debug("PassThrough::send() response had {LEN} bytes", "LEN",
+ response.size());
}
else
{
- log<level::ERR>("PassThrough::send() Invalid OCC response");
+ lg2::error("PassThrough::send() Invalid OCC response");
dump_hex(response);
}
}
else
{
- log<level::ERR>(
- std::format(
- "PassThrough::send(): OCC command failed with status {}",
- uint32_t(status))
- .c_str());
+ lg2::error(
+ "PassThrough::send(): OCC command failed with status {STATUS}",
+ "STATUS", status);
}
return response;
@@ -149,42 +137,34 @@
if (!pmode)
{
- log<level::ERR>("PassThrough::setMode: PowerMode is not defined!");
+ lg2::error("PassThrough::setMode: PowerMode is not defined!");
return false;
}
if (!pmode->isValidMode(SysPwrMode(mode)))
{
- log<level::ERR>(
- std::format(
- "PassThrough::setMode() Unsupported mode {} requested (0x{:04X})",
- newMode, modeData)
- .c_str());
+ lg2::error(
+ "PassThrough::setMode() Unsupported mode {MODE} requested ({DATA})",
+ "MODE", newMode, "DATA", modeData);
return false;
}
if (((newMode == SysPwrMode::FFO) || (newMode == SysPwrMode::SFP)) &&
(modeData == 0))
{
- log<level::ERR>(
- std::format(
- "PassThrough::setMode() Mode {} requires non-zero frequency point.",
- newMode)
- .c_str());
+ lg2::error(
+ "PassThrough::setMode() Mode {MODE} requires non-zero frequency point.",
+ "MODE", newMode);
return false;
}
- log<level::INFO>(
- std::format("PassThrough::setMode() Setting Power Mode {} (data: {})",
- newMode, modeData)
- .c_str());
+ lg2::info("PassThrough::setMode() Setting Power Mode {MODE} (data: {DATA})",
+ "MODE", uint8_t(newMode), "DATA", modeData);
return pmode->setMode(newMode, modeData);
#else
- log<level::DEBUG>(
- std::format(
- "PassThrough::setMode() No support to setting Power Mode {} (data: {})",
- mode, modeData)
- .c_str());
+ lg2::debug(
+ "PassThrough::setMode() No support to setting Power Mode {MODE} (data: {DATA})",
+ "MODE", mode, "DATA", modeData);
return false;
#endif
}
diff --git a/occ_presence.cpp b/occ_presence.cpp
index 73ccf66..b7d4276 100644
--- a/occ_presence.cpp
+++ b/occ_presence.cpp
@@ -10,7 +10,7 @@
#include <org/open_power/OCC/Device/error.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace open_power
@@ -46,9 +46,8 @@
auto occsPresent = std::stoi(data, nullptr, 0);
if (manager.getNumOCCs() != occsPresent)
{
- log<level::ERR>(std::format("OCC presence mismatch - BMC: {}, OCC: {}",
- manager.getNumOCCs(), occsPresent)
- .c_str());
+ lg2::error("OCC presence mismatch - BMC: {BNUM}, OCC: {ONUM}", "BNUM",
+ manager.getNumOCCs(), "ONUM", occsPresent);
if (callBack)
{
callBack(occsPresent);
diff --git a/occ_status.cpp b/occ_status.cpp
index 4b6e276..c664d11 100644
--- a/occ_status.cpp
+++ b/occ_status.cpp
@@ -5,10 +5,9 @@
#include "powermode.hpp"
#include "utils.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <filesystem>
-#include <format>
namespace open_power
{
@@ -25,9 +24,8 @@
{
if (value != this->occActive())
{
- log<level::INFO>(std::format("Status::occActive OCC{} changed to {}",
- instance, value)
- .c_str());
+ lg2::info("Status::occActive OCC{INST} changed to {STATE}", "INST",
+ instance, "STATE", value);
if (value)
{
// Clear prior throttle reason (before setting device active)
@@ -48,11 +46,9 @@
{
// Failed to add watch for throttle events, request reset to try
// to recover comm
- log<level::ERR>(
- std::format(
- "Status::occActive: Unable to add error watch(s) for OCC{} watch: {}",
- instance, e.what())
- .c_str());
+ lg2::error(
+ "Status::occActive: Unable to add error watch(s) for OCC{INST} watch: {ERROR}",
+ "INST", instance, "ERROR", e.what());
deviceError(Error::Descriptor(OCC_COMM_ERROR_PATH));
return Base::Status::occActive(false);
}
@@ -127,11 +123,9 @@
{
// Failed to add watch for throttle events, request reset to try to
// recover comm
- log<level::ERR>(
- std::format(
- "Status::occActive: Unable to add error watch(s) again for OCC{} watch: {}",
- instance, e.what())
- .c_str());
+ lg2::error(
+ "Status::occActive: Unable to add error watch(s) again for OCC{INST} watch: {ERROR}",
+ "INST", instance, "ERROR", e.what());
deviceError(Error::Descriptor(OCC_COMM_ERROR_PATH));
return Base::Status::occActive(false);
}
@@ -176,10 +170,8 @@
// Sends message to host control command handler to reset OCC
void Status::resetOCC()
{
- log<level::INFO>(
- std::format(">>Status::resetOCC() - requesting reset for OCC{}",
- instance)
- .c_str());
+ lg2::info(">>Status::resetOCC() - requesting reset for OCC{INST}", "INST",
+ instance);
this->occActive(false);
#ifdef PLDM
if (resetCallBack)
@@ -215,9 +207,8 @@
msg.read(cmdCompleted, cmdStatus);
- log<level::DEBUG>("Host control signal values",
- entry("COMMAND=%s", cmdCompleted.c_str()),
- entry("STATUS=%s", cmdStatus.c_str()));
+ lg2::debug("Host control signal values: command={CMD}, status={STATUS}",
+ "CMD", cmdCompleted, "STATUS", cmdStatus);
if (Control::Host::convertResultFromString(cmdStatus) !=
Control::Host::Result::Success)
@@ -226,9 +217,9 @@
Control::Host::Command::OCCReset)
{
// Must be a Timeout. Log an Error trace
- log<level::ERR>(
- "Error resetting the OCC.", entry("PATH=%s", path.c_str()),
- entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance))));
+ lg2::error(
+ "Error resetting the OCC: path={PATH}, sensorid={SENSOR}",
+ "PATH", path, "SENSOR", std::get<0>(sensorMap.at(instance)));
}
}
return;
@@ -258,11 +249,9 @@
status = pmode->sendModeChange();
if (status != CmdStatus::SUCCESS)
{
- log<level::ERR>(
- std::format(
- "Status::occsWentActive: OCC mode change failed with status {}",
- status)
- .c_str());
+ lg2::error(
+ "Status::occsWentActive: OCC mode change failed with status {STATUS}",
+ "STATUS", status);
// Disable and reset to try recovering
deviceError();
@@ -281,10 +270,9 @@
{
// Get latest readings from manager
manager.getAmbientData(ambientValid, ambientTemp, altitude);
- log<level::DEBUG>(
- std::format("sendAmbient: valid: {}, Ambient: {}C, altitude: {}m",
- ambientValid, ambientTemp, altitude)
- .c_str());
+ lg2::debug(
+ "sendAmbient: valid: {VALID}, Ambient: {TEMP}C, altitude: {ALT}m",
+ "VALID", ambientValid, "TEMP", ambientTemp, "ALT", altitude);
}
std::vector<std::uint8_t> cmd, rsp;
@@ -300,10 +288,9 @@
cmd.push_back(0x00); // Reserved (3 bytes)
cmd.push_back(0x00);
cmd.push_back(0x00);
- log<level::DEBUG>(std::format("sendAmbient: SEND_AMBIENT "
- "command to OCC{} ({} bytes)",
- instance, cmd.size())
- .c_str());
+ lg2::debug("sendAmbient: SEND_AMBIENT "
+ "command to OCC{INST} ({SIZE} bytes)",
+ "INST", instance, "SIZE", cmd.size());
status = occCmd.send(cmd, rsp);
if (status == CmdStatus::SUCCESS)
{
@@ -311,33 +298,26 @@
{
if (RspStatus::SUCCESS != RspStatus(rsp[2]))
{
- log<level::ERR>(
- std::format(
- "sendAmbient: SEND_AMBIENT failed with rspStatus 0x{:02X}",
- rsp[2])
- .c_str());
+ lg2::error(
+ "sendAmbient: SEND_AMBIENT failed with rspStatus {STATUS}",
+ "STATUS", lg2::hex, rsp[2]);
dump_hex(rsp);
status = CmdStatus::FAILURE;
}
}
else
{
- log<level::ERR>(
- std::format(
- "sendAmbient: INVALID SEND_AMBIENT response length:{}",
- rsp.size())
- .c_str());
+ lg2::error(
+ "sendAmbient: INVALID SEND_AMBIENT response length:{SIZE}",
+ "SIZE", rsp.size());
dump_hex(rsp);
status = CmdStatus::FAILURE;
}
}
else
{
- log<level::ERR>(
- std::format(
- "sendAmbient: SEND_AMBIENT FAILED! with status 0x{:02X}",
- status)
- .c_str());
+ lg2::error("sendAmbient: SEND_AMBIENT FAILED! with status {STATUS}",
+ "STATUS", lg2::hex, uint8_t(status));
if (status == CmdStatus::COMM_FAILURE)
{
@@ -354,11 +334,9 @@
{
if (this->occActive())
{
- log<level::INFO>(
- std::format(
- "safeStateDelayExpired: OCC{} state missing or not valid, requesting reset",
- instance)
- .c_str());
+ lg2::info(
+ "safeStateDelayExpired: OCC{INST} state missing or not valid, requesting reset",
+ "INST", instance);
// Disable and reset to try recovering
deviceError(Error::Descriptor(SAFE_ERROR_PATH));
}
@@ -375,10 +353,9 @@
if (!hwmonPath.empty())
{
- log<level::WARNING>(
- std::format("Status::getHwmonPath(): path no longer exists: {}",
- hwmonPath.c_str())
- .c_str());
+ lg2::warning(
+ "Status::getHwmonPath(): path no longer exists: {PATH}", "PATH",
+ hwmonPath);
hwmonPath.clear();
}
@@ -402,11 +379,9 @@
{
if (!tracedFail[instance])
{
- log<level::ERR>(
- std::format(
- "Status::getHwmonPath(): Found multiple ({}) hwmon paths!",
- numDirs)
- .c_str());
+ lg2::error(
+ "Status::getHwmonPath(): Found multiple ({NUM}) hwmon paths!",
+ "NUM", numDirs);
tracedFail[instance] = true;
}
}
@@ -415,11 +390,9 @@
{
if (!tracedFail[instance])
{
- log<level::ERR>(
- std::format(
- "Status::getHwmonPath(): error accessing {}: {}",
- prefixPath.c_str(), e.what())
- .c_str());
+ lg2::error(
+ "Status::getHwmonPath(): error accessing {PATH}: {ERROR}",
+ "PATH", prefixPath, "ERROR", e.what());
tracedFail[instance] = true;
}
}
@@ -469,11 +442,9 @@
{
errorBits += " badbit";
}
- log<level::ERR>(
- std::format(
- "readOccState: Failed to read OCC{} state: Read error on I/O operation -{}",
- instance, errorBits)
- .c_str());
+ lg2::error(
+ "readOccState: Failed to read OCC{INST} state: Read error on I/O operation - {ERROR}",
+ "INST", instance, "ERROR", errorBits);
lastOccReadStatus = -1;
}
goodFile = false;
@@ -482,11 +453,10 @@
if (goodFile && (state != lastState))
{
// Trace OCC state changes
- log<level::INFO>(
- std::format(
- "Status::readOccState: OCC{} state 0x{:02X} (lastState: 0x{:02X})",
- instance, state, lastState)
- .c_str());
+ lg2::info(
+ "Status::readOccState: OCC{INST} state {STATE} (lastState: {PRIOR})",
+ "INST", instance, "STATE", lg2::hex, state, "PRIOR", lg2::hex,
+ lastState);
lastState = state;
#ifdef POWER10
if (OccState(state) == OccState::ACTIVE)
@@ -505,11 +475,9 @@
CmdStatus status = sendAmbient();
if (status != CmdStatus::SUCCESS)
{
- log<level::ERR>(
- std::format(
- "readOccState: Sending Ambient failed with status {}",
- status)
- .c_str());
+ lg2::error(
+ "readOccState: Sending Ambient failed with status {STATUS}",
+ "STATUS", status);
}
}
@@ -532,11 +500,9 @@
// OCC is in SAFE or some other unsupported state
if (!safeStateDelayTimer.isEnabled())
{
- log<level::ERR>(
- std::format(
- "readOccState: Invalid OCC{} state of {}, starting safe state delay timer",
- instance, state)
- .c_str());
+ lg2::error(
+ "readOccState: Invalid OCC{INST} state of {STATE}, starting safe state delay timer",
+ "INST", instance, "STATE", state);
// start safe delay timer (before requesting reset)
using namespace std::literals::chrono_literals;
safeStateDelayTimer.restartOnce(60s);
@@ -569,11 +535,9 @@
// If not able to read, OCC may be offline
if (openErrno != lastOccReadStatus)
{
- log<level::ERR>(
- std::format(
- "Status::readOccState: open/read failed trying to read OCC{} state (open errno={})",
- instance, openErrno)
- .c_str());
+ lg2::error(
+ "Status::readOccState: open/read failed trying to read OCC{INST} state (open errno={ERROR})",
+ "INST", instance, "ERROR", openErrno);
lastOccReadStatus = openErrno;
}
}
@@ -582,11 +546,10 @@
// else this failed due to state not valid.
if (state != lastState)
{
- log<level::ERR>(
- std::format(
- "Status::readOccState: OCC{} Invalid state 0x{:02X} (last state: 0x{:02X})",
- instance, state, lastState)
- .c_str());
+ lg2::error(
+ "Status::readOccState: OCC{INST} Invalid state {STATE} (last state: {PRIOR})",
+ "INST", instance, "STATE", lg2::hex, state, "PRIOR",
+ lg2::hex, lastState);
}
}
@@ -601,10 +564,8 @@
}
else
{
- log<level::ERR>(
- std::format("readOccState: failed to read OCC{} state!",
- instance)
- .c_str());
+ lg2::error("readOccState: failed to read OCC{INST} state!", "INST",
+ instance);
// State could not be determined, set it to NO State.
lastState = 0;
@@ -624,11 +585,9 @@
{
if (lastOccReadStatus != 0)
{
- log<level::INFO>(
- std::format(
- "Status::readOccState: successfully read OCC{} state: {}",
- instance, state)
- .c_str());
+ lg2::info(
+ "Status::readOccState: successfully read OCC{INST} state: {STATE}",
+ "INST", instance, "STATE", state);
lastOccReadStatus = 0; // no error
}
}
@@ -667,22 +626,19 @@
{
if (newThrottleCause == THROTTLED_NONE)
{
- log<level::DEBUG>(
- std::format(
- "updateThrottle: OCC{} no longer throttled (prior reason: {})",
- instance, throttleCause)
- .c_str());
+ lg2::debug(
+ "updateThrottle: OCC{INST} no longer throttled (prior reason: {REASON})",
+ "INST", instance, "REASON", throttleCause);
throttleCause = THROTTLED_NONE;
throttleHandle->throttled(false);
throttleHandle->throttleCauses({});
}
else
{
- log<level::DEBUG>(
- std::format(
- "updateThrottle: OCC{} is throttled with reason {} (prior reason: {})",
- instance, newThrottleCause, throttleCause)
- .c_str());
+ lg2::debug(
+ "updateThrottle: OCC{INST} is throttled with reason {REASON} (prior reason: {PRIOR})",
+ "INST", instance, "REASON", newThrottleCause, "PRIOR",
+ throttleCause);
throttleCause = newThrottleCause;
std::vector<ThrottleObj::ThrottleReasons> updatedCauses;
@@ -712,10 +668,8 @@
void Status::readProcAssociation()
{
std::string managingPath = path + "/power_managing";
- log<level::DEBUG>(
- std::format("readProcAssociation: getting endpoints for {} ({})",
- managingPath, path)
- .c_str());
+ lg2::debug("readProcAssociation: getting endpoints for {MANAGE} ({PATH})",
+ "MANAGE", managingPath, "PATH", path);
try
{
utils::PropertyValue procPathProperty{};
@@ -725,27 +679,21 @@
if (result.size() > 0)
{
procPath = result[0];
- log<level::INFO>(
- std::format("readProcAssociation: OCC{} has proc={}", instance,
- procPath.c_str())
- .c_str());
+ lg2::info("readProcAssociation: OCC{INST} has proc={PATH}", "INST",
+ instance, "PATH", procPath);
}
else
{
- log<level::ERR>(
- std::format(
- "readProcAssociation: No processor associated with OCC{} / {}",
- instance, path)
- .c_str());
+ lg2::error(
+ "readProcAssociation: No processor associated with OCC{INST} / {PATH}",
+ "INST", instance, "PATH", path);
}
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format(
- "readProcAssociation: Unable to get proc assocated with {} - {}",
- path, e.what())
- .c_str());
+ lg2::error(
+ "readProcAssociation: Unable to get proc assocated with {PATH} - {ERROR}",
+ "PATH", path, "ERROR", e.what());
procPath = {};
}
}
diff --git a/pldm.cpp b/pldm.cpp
index 4e57ece..d835fbe 100644
--- a/pldm.cpp
+++ b/pldm.cpp
@@ -13,7 +13,7 @@
#include <libpldm/transport/mctp-demux.h>
#include <poll.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/exception.hpp>
@@ -21,13 +21,10 @@
#include <sdeventplus/source/time.hpp>
#include <algorithm>
-#include <format>
namespace pldm
{
-using namespace phosphor::logging;
-
using namespace sdeventplus;
using namespace sdeventplus::source;
constexpr auto clockId = sdeventplus::ClockId::RealTime;
@@ -59,11 +56,9 @@
{
if (!tracedError)
{
- log<level::ERR>(
- std::format(
- "fetchSensorInfo: Failed to find stateSetID:{} PDR: {}",
- stateSetId, e.what())
- .c_str());
+ lg2::error(
+ "fetchSensorInfo: Failed to find stateSetID:{ID} PDR: {ERR}",
+ "ID", stateSetId, "ERR", e.what());
tracedError = true;
}
}
@@ -72,11 +67,8 @@
{
if (!tracedError)
{
- log<level::ERR>(
- std::format(
- "fetchSensorInfo: state sensor PDRs ({}) not present",
- stateSetId)
- .c_str());
+ lg2::error("fetchSensorInfo: state sensor PDRs ({ID}) not present",
+ "ID", stateSetId);
tracedError = true;
}
return;
@@ -85,8 +77,7 @@
// Found PDR
if (tracedError)
{
- log<level::INFO>(
- std::format("fetchSensorInfo: found {} PDRs", pdrs.size()).c_str());
+ lg2::info("fetchSensorInfo: found {NUM} PDRs", "NUM", pdrs.size());
tracedError = false;
}
@@ -114,7 +105,7 @@
if (!offsetFound)
{
- log<level::ERR>("pldm: state sensor PDR not found");
+ lg2::error("pldm: state sensor PDR not found");
return;
}
@@ -174,38 +165,31 @@
static_cast<EventState>(
PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE))
{
- log<level::INFO>(
- std::format("PLDM: OCC{} is RUNNING", instance).c_str());
+ lg2::info("PLDM: OCC{INST} is RUNNING", "INST", instance);
isRunning = true;
}
else if (eventState ==
static_cast<EventState>(
PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED))
{
- log<level::INFO>(
- std::format("PLDM: OCC{} has now STOPPED", instance)
- .c_str());
+ lg2::info("PLDM: OCC{INST} has now STOPPED", "INST", instance);
}
else if (eventState ==
static_cast<EventState>(
PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT))
{
- log<level::ERR>(
- std::format(
- "PLDM: OCC{} has now STOPPED and system is in SAFE MODE",
- instance)
- .c_str());
+ lg2::error(
+ "PLDM: OCC{INST} has now STOPPED and system is in SAFE MODE",
+ "INST", instance);
// Setting safe mode true
safeModeCallBack(true);
}
else
{
- log<level::WARNING>(
- std::format(
- "PLDM: Unexpected OCC Active sensor state {} for OCC{}",
- eventState, instance)
- .c_str());
+ lg2::warning(
+ "PLDM: Unexpected OCC Active sensor state {STATE} for OCC{INST}",
+ "STATE", eventState, "INST", instance);
validEvent = false;
}
if (validEvent)
@@ -235,20 +219,16 @@
outstandingHResets.erase(match);
if (eventState == static_cast<EventState>(SBE_HRESET_NOT_READY))
{
- log<level::ERR>(
- std::format("pldm: HRESET is NOT READY (OCC{})",
- instance)
- .c_str());
+ lg2::error("pldm: HRESET is NOT READY (OCC{INST})", "INST",
+ instance);
// Stop OCC comm - OCC not usable until it becomes READY
occActiveCallBack(instance, false);
// Collect SBE FFDC
sbeCallBack(instance, false);
// Try PM Complex reset
- log<level::ERR>(
- std::format(
- "sensorEvent: Requesting OCC reset for OCC{}",
- instance)
- .c_str());
+ lg2::error(
+ "sensorEvent: Requesting OCC reset for OCC{INST}",
+ "INST", instance);
resetOCC(resetInstance);
}
else if (eventState ==
@@ -265,11 +245,9 @@
{
if (eventState ==
static_cast<EventState>(SBE_HRESET_FAILED))
- log<level::ERR>(
- std::format(
- "pldm: Unexpected HRESET state {} (OCC{})",
- eventState, instance)
- .c_str());
+ lg2::error(
+ "pldm: Unexpected HRESET state {STATE} (OCC{INST})",
+ "STATE", eventState, "INST", instance);
sbeCallBack(instance, false);
}
}
@@ -299,44 +277,32 @@
{
if (!sensorToOCCInstance.empty())
{
- log<level::INFO>(
- std::format("clearData: Clearing sensorToOCCInstance ({} entries)",
- sensorToOCCInstance.size())
- .c_str());
+ lg2::info("clearData: Clearing sensorToOCCInstance ({NUM} entries)",
+ "NUM", sensorToOCCInstance.size());
for (auto entry : sensorToOCCInstance)
{
- log<level::INFO>(
- std::format("clearData: OCC{} / sensorID: 0x{:04X}",
- entry.second, entry.first)
- .c_str());
+ lg2::info("clearData: OCC{INST} / sensorID: {ID}", "INST",
+ entry.second, "ID", lg2::hex, entry.first);
occActiveCallBack(entry.second, false);
}
sensorToOCCInstance.clear();
}
if (!occInstanceToEffecter.empty())
{
- log<level::DEBUG>(
- std::format(
- "clearData: Clearing occInstanceToEffecter ({} entries)",
- occInstanceToEffecter.size())
- .c_str());
+ lg2::debug("clearData: Clearing occInstanceToEffecter ({NUM} entries)",
+ "NUM", occInstanceToEffecter.size());
occInstanceToEffecter.clear();
}
if (!sensorToSBEInstance.empty())
{
- log<level::DEBUG>(
- std::format("clearData: Clearing sensorToSBEInstance ({} entries)",
- sensorToSBEInstance.size())
- .c_str());
+ lg2::debug("clearData: Clearing sensorToSBEInstance ({NUM} entries)",
+ "NUM", sensorToSBEInstance.size());
sensorToSBEInstance.clear();
}
if (!sbeInstanceToEffecter.empty())
{
- log<level::DEBUG>(
- std::format(
- "clearData: Clearing sbeInstanceToEffecter ({} entries)",
- sbeInstanceToEffecter.size())
- .c_str());
+ lg2::debug("clearData: Clearing sbeInstanceToEffecter ({NUM} entries)",
+ "NUM", sbeInstanceToEffecter.size());
sbeInstanceToEffecter.clear();
}
}
@@ -360,13 +326,13 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("pldm: Failed to fetch the state effecter PDRs",
- entry("ERROR=%s", e.what()));
+ lg2::error("pldm: Failed to fetch the state effecter PDRs: {ERR}",
+ "ERR", e.what());
}
if (!pdrs.size())
{
- log<level::ERR>("pldm: state effecter PDRs not present");
+ lg2::error("pldm: state effecter PDRs not present");
return;
}
@@ -448,8 +414,8 @@
requestMsg);
if (rc != PLDM_SUCCESS)
{
- log<level::ERR>("encode set effecter states request returned error ",
- entry("RC=%d", rc));
+ lg2::error("encode set effecter states request returned error rc={RC}",
+ "RC", rc);
request.clear();
}
return request;
@@ -470,11 +436,9 @@
auto effecterEntry = occInstanceToEffecter.find(occInstanceId);
if (effecterEntry == occInstanceToEffecter.end())
{
- log<level::ERR>(
- std::format(
- "pldm: Failed to find a matching effecter for OCC instance {}",
- occInstanceId)
- .c_str());
+ lg2::error(
+ "pldm: Failed to find a matching effecter for OCC instance {INST}",
+ "INST", occInstanceId);
return;
}
@@ -486,8 +450,7 @@
if (request.empty())
{
- log<level::ERR>(
- "pldm: SetStateEffecterStates OCC reset request empty");
+ lg2::error("pldm: SetStateEffecterStates OCC reset request empty");
return;
}
@@ -498,9 +461,8 @@
}
else
{
- log<level::ERR>(
- std::format("resetOCC: HOST is not running (OCC{})", occInstanceId)
- .c_str());
+ lg2::error("resetOCC: HOST is not running (OCC{INST})", "INST",
+ occInstanceId);
clearData();
}
}
@@ -519,9 +481,9 @@
auto effecterEntry = sbeInstanceToEffecter.find(sbeInstanceId);
if (effecterEntry == sbeInstanceToEffecter.end())
{
- log<level::ERR>(
- "pldm: Failed to find a matching effecter for SBE instance",
- entry("SBE=%d", sbeInstanceId));
+ lg2::error(
+ "pldm: Failed to find a matching effecter for SBE instance {INST}",
+ "INST", sbeInstanceId);
return;
}
@@ -532,8 +494,7 @@
if (request.empty())
{
- log<level::ERR>(
- "pldm: SetStateEffecterStates HRESET request empty");
+ lg2::error("pldm: SetStateEffecterStates HRESET request empty");
return;
}
@@ -545,9 +506,8 @@
}
else
{
- log<level::ERR>(std::format("sendHRESET: HOST is not running (OCC{})",
- sbeInstanceId)
- .c_str());
+ lg2::error("sendHRESET: HOST is not running (OCC{INST})", "INST",
+ sbeInstanceId);
clearData();
}
}
@@ -567,20 +527,16 @@
if (rc)
{
- log<level::ERR>(
- std::format(
- "getPldmInstanceId: Failed to alloc ID for TID {}. RC{}",
- tid, rc)
- .c_str());
+ lg2::error(
+ "getPldmInstanceId: Failed to alloc ID for TID {TID}. RC{RC}",
+ "TID", tid, "RC", rc);
return false;
}
pldmInstanceID.emplace(id);
if (!throttleTraces)
{
- log<level::INFO>(
- std::format("got id {} and set PldmInstanceId to {}", id,
- pldmInstanceID.value())
- .c_str());
+ lg2::info("got id {ID} and set PldmInstanceId to {INST}", "ID", id,
+ "INST", pldmInstanceID.value());
}
}
return true;
@@ -594,18 +550,15 @@
pldmInstanceID.value());
if (rc)
{
- log<level::ERR>(
- std::format(
- "freePldmInstanceId: Failed to free ID {} for TID {}. RC{}",
- pldmInstanceID.value(), tid, rc)
- .c_str());
+ lg2::error(
+ "freePldmInstanceId: Failed to free ID {ID} for TID {TID}. RC{RC}",
+ "ID", pldmInstanceID.value(), "TID", tid, "RC", rc);
return;
}
if (!throttleTraces)
{
- log<level::INFO>(
- std::format("Freed PLDM instance ID {}", pldmInstanceID.value())
- .c_str());
+ lg2::info("Freed PLDM instance ID {ID}", "ID",
+ pldmInstanceID.value());
}
pldmInstanceID = std::nullopt;
}
@@ -617,21 +570,17 @@
int rc = pldm_transport_mctp_demux_init(&impl.mctpDemux);
if (rc)
{
- log<level::ERR>(
- std::format(
- "openMctpDemuxTransport: Failed to init MCTP demux transport, errno={}/{}",
- rc, strerror(rc))
- .c_str());
+ lg2::error(
+ "openMctpDemuxTransport: Failed to init MCTP demux transport, errno={ERR}/{STR}",
+ "ERR", rc, "STR", strerror(rc));
return -1;
}
if (pldm_transport_mctp_demux_map_tid(impl.mctpDemux, mctpEid, mctpEid))
{
- log<level::ERR>(
- std::format(
- "openMctpDemuxTransport: Failed to setup tid to eid mapping, errno={}/{}",
- errno, strerror(errno))
- .c_str());
+ lg2::error(
+ "openMctpDemuxTransport: Failed to setup tid to eid mapping, errno={ERR}/{STR}",
+ "ERR", errno, "STR", strerror(errno));
pldmClose();
return -1;
}
@@ -640,20 +589,16 @@
struct pollfd pollfd;
if (pldm_transport_mctp_demux_init_pollfd(pldmTransport, &pollfd))
{
- log<level::ERR>(
- std::format(
- "openMctpDemuxTransport: Failed to get pollfd , errno={}/{}",
- errno, strerror(errno))
- .c_str());
+ lg2::error(
+ "openMctpDemuxTransport: Failed to get pollfd , errno={ERR}/{STR}",
+ "ERR", errno, "STR", strerror(errno));
pldmClose();
return -1;
}
pldmFd = pollfd.fd;
if (!throttleTraces)
{
- log<level::INFO>(
- std::format("openMctpDemuxTransport: pldmFd has fd={}", pldmFd)
- .c_str());
+ lg2::info("openMctpDemuxTransport: pldmFd has fd={FD}", "FD", pldmFd);
}
return 0;
}
@@ -664,21 +609,17 @@
int rc = pldm_transport_af_mctp_init(&impl.afMctp);
if (rc)
{
- log<level::ERR>(
- std::format(
- "openAfMctpTransport: Failed to init af MCTP transport, errno={}/{}",
- rc, strerror(rc))
- .c_str());
+ lg2::error(
+ "openAfMctpTransport: Failed to init af MCTP transport, errno={ERR}/{STR}",
+ "ERR", rc, "STR", strerror(rc));
return -1;
}
if (pldm_transport_af_mctp_map_tid(impl.afMctp, mctpEid, mctpEid))
{
- log<level::ERR>(
- std::format(
- "openAfMctpTransport: Failed to setup tid to eid mapping, errno={}/{}",
- errno, strerror(errno))
- .c_str());
+ lg2::error(
+ "openAfMctpTransport: Failed to setup tid to eid mapping, errno={ERR}/{STR}",
+ "ERR", errno, "STR", strerror(errno));
pldmClose();
return -1;
}
@@ -687,20 +628,16 @@
struct pollfd pollfd;
if (pldm_transport_af_mctp_init_pollfd(pldmTransport, &pollfd))
{
- log<level::ERR>(
- std::format(
- "openAfMctpTransport: Failed to get pollfd , errno={}/{}",
- errno, strerror(errno))
- .c_str());
+ lg2::error(
+ "openAfMctpTransport: Failed to get pollfd , errno={ERR}/{STR}",
+ "ERR", errno, "STR", strerror(errno));
pldmClose();
return -1;
}
pldmFd = pollfd.fd;
if (!throttleTraces)
{
- log<level::INFO>(
- std::format("openAfMctpTransport: pldmFd has fd={}", pldmFd)
- .c_str());
+ lg2::info("openAfMctpTransport: pldmFd has fd={FD}", "FD", pldmFd);
}
return 0;
}
@@ -709,10 +646,8 @@
{
if (pldmTransport)
{
- log<level::ERR>(
- std::format("pldmOpen: pldmTransport already setup!, errno={}/{}",
- errno, strerror(errno))
- .c_str());
+ lg2::error("pldmOpen: pldmTransport already setup!, errno={ERR}/{STR}",
+ "ERR", errno, "STR", strerror(errno));
return -1;
}
#if defined(PLDM_TRANSPORT_WITH_MCTP_DEMUX)
@@ -720,10 +655,8 @@
#elif defined(PLDM_TRANSPORT_WITH_AF_MCTP)
return openAfMctpTransport();
#else
- log<level::ERR>(
- std::format("pldmOpen: Undefined pldmTransport!, errno={}/{}", errno,
- strerror(errno))
- .c_str());
+ lg2::error("pldmOpen: Undefined pldmTransport!, errno={ERR}/{STR}", "ERR",
+ errno, "STR", strerror(errno));
return -1;
#endif
@@ -735,7 +668,7 @@
{
if (!pldmInstanceID)
{
- log<level::ERR>("sendPldm: No PLDM Instance ID found!");
+ lg2::error("sendPldm: No PLDM Instance ID found!");
return;
}
@@ -744,8 +677,7 @@
{
if (!throttleTraces)
{
- log<level::ERR>(
- std::format("sendPldm: pldmOpen failed rc={}", rc).c_str());
+ lg2::error("sendPldm: pldmOpen failed rc={RC}", "RC", rc);
}
freePldmInstanceId();
return;
@@ -768,11 +700,10 @@
// Send PLDM request
if (!throttleTraces)
{
- log<level::INFO>(
- std::format(
- "sendPldm: calling pldm_transport_send_msg(OCC{}, instance:{}, {} bytes, timeout {})",
- instance, pldmInstanceID.value(), request.size(), timeout)
- .c_str());
+ lg2::info("sendPldm: calling pldm_transport_send_msg(OCC{INST}, "
+ "instance:{ID}, {LEN} bytes, timeout {TO})",
+ "INST", instance, "ID", pldmInstanceID.value(), "LEN",
+ request.size(), "TO", timeout.count());
}
pldmResponseReceived = false;
pldmResponseTimeout = false;
@@ -782,14 +713,12 @@
auto sendErrno = errno;
if (pldmRc != PLDM_REQUESTER_SUCCESS)
{
- log<level::ERR>(
- std::format(
- "sendPldm: pldm_transport_send_msg failed with rc={} and errno={}/{}",
- static_cast<
- std::underlying_type_t<pldm_requester_error_codes>>(
- pldmRc),
- sendErrno, strerror(sendErrno))
- .c_str());
+ lg2::error(
+ "sendPldm: pldm_transport_send_msg failed with rc={RC} and errno={ERR}/{STR}",
+ "RC",
+ static_cast<std::underlying_type_t<pldm_requester_error_codes>>(
+ pldmRc),
+ "ERR", sendErrno, "STR", strerror(sendErrno));
pldmClose();
return;
}
@@ -803,25 +732,24 @@
{
if (!throttleTraces)
{
- log<level::INFO>(
- std::format(
- "sendPldm: calling pldm_transport_send_msg(mctpID:{}, fd:{}, {} bytes) for OCC{}",
- mctpEid, pldmFd, request.size(), instance)
- .c_str());
+ lg2::info(
+ "sendPldm: calling pldm_transport_send_msg(mctpID:{ID}, fd:{FD}, "
+ "{LEN} bytes) for OCC{INST}",
+ "ID", mctpEid, "FD", pldmFd, "LEN", request.size(), "INST",
+ instance);
}
auto rc = pldm_transport_send_msg(pldmTransport, pldmTID,
request.data(), request.size());
auto sendErrno = errno;
if (rc)
{
- log<level::ERR>(
- std::format(
- "sendPldm: pldm_transport_send_msg(mctpID:{}, fd:{}, {} bytes) failed with rc={} and errno={}/{}",
- mctpEid, pldmFd, request.size(),
- static_cast<
- std::underlying_type_t<pldm_requester_error_codes>>(rc),
- sendErrno, strerror(sendErrno))
- .c_str());
+ lg2::error(
+ "sendPldm: pldm_transport_send_msg(mctpID:{ID}, fd:{FD}, {LEN} bytes) "
+ "failed with rc={RC} and errno={ERR}/{STR}",
+ "ID", mctpEid, "FD", pldmFd, "LEN", request.size(), "RC",
+ static_cast<std::underlying_type_t<pldm_requester_error_codes>>(
+ rc),
+ "ERR", sendErrno, "STR", strerror(sendErrno));
}
pldmClose();
}
@@ -844,11 +772,9 @@
}
if (rc < 0)
{
- log<level::ERR>(
- std::format(
- "registerPldmRspCallback: sd_event_add_io: Error({})={} : fd={} (msgType={})",
- rc, strerror(-rc), pldmFd, msgType)
- .c_str());
+ lg2::error(
+ "registerPldmRspCallback: sd_event_add_io: Error({ERR})={STR} : fd={FD} (msgType={MSG})",
+ "ERR", rc, "STR", strerror(-rc), "FD", pldmFd, "MSG", msgType);
}
else
{
@@ -864,11 +790,10 @@
{
if (!throttleTraces)
{
- log<level::WARNING>(
- std::format(
- "pldmRspExpired: timerCallback - timeout waiting for pldm response to msg:{} for OCC{}",
- msgType, pldmResponseOcc)
- .c_str());
+ lg2::warning(
+ "pldmRspExpired: timerCallback - timeout waiting for pldm "
+ "response to msg:{MSG} for OCC{INST}",
+ "MSG", msgType, "INST", pldmResponseOcc);
}
pldmResponseTimeout = true;
if (pldmFd)
@@ -878,10 +803,8 @@
if (msgType == MSG_OCC_RESET)
{
// reset not acked, try again
- log<level::ERR>(
- std::format("pldmRspExpired: retrying reset request for OCC{}",
- pldmResponseOcc)
- .c_str());
+ lg2::error("pldmRspExpired: retrying reset request for OCC{INST}",
+ "INST", pldmResponseOcc);
resetOCC(pldmResponseOcc);
}
}
@@ -915,8 +838,7 @@
{
if (!(revents & EPOLLIN))
{
- log<level::INFO>(
- std::format("pldmRspCallback - revents={:08X}", revents).c_str());
+ lg2::info("pldmRspCallback - revents={NUM}", "NUM", lg2::hex, revents);
return -1;
}
@@ -924,8 +846,7 @@
if (!pldmIface->pldmInstanceID)
{
- log<level::ERR>(
- "pldmRspCallback: No outstanding PLDM Instance ID found");
+ lg2::error("pldmRspCallback: No outstanding PLDM Instance ID found");
return -1;
}
@@ -935,11 +856,9 @@
if (!throttleTraces)
{
- log<level::INFO>(
- std::format(
- "pldmRspCallback: calling pldm_transport_recv_msg() instance:{}",
- pldmIface->pldmInstanceID.value())
- .c_str());
+ lg2::info(
+ "pldmRspCallback: calling pldm_transport_recv_msg() instance:{INST}",
+ "INST", pldmIface->pldmInstanceID.value());
}
auto rc = pldm_transport_recv_msg(pldmIface->pldmTransport, &pldmTID,
(void**)&responseMsg, &responseMsgSize);
@@ -948,13 +867,12 @@
{
if (!throttleTraces)
{
- log<level::ERR>(
- std::format(
- "pldmRspCallback: pldm_transport_recv_msg failed with rc={}, errno={}/{}",
- static_cast<
- std::underlying_type_t<pldm_requester_error_codes>>(rc),
- lastErrno, strerror(lastErrno))
- .c_str());
+ lg2::error(
+ "pldmRspCallback: pldm_transport_recv_msg failed with rc={RC}, errno={ERR}/{STR}",
+ "RC",
+ static_cast<std::underlying_type_t<pldm_requester_error_codes>>(
+ rc),
+ "ERR", lastErrno, "STR", strerror(lastErrno));
}
return -1;
}
@@ -962,11 +880,9 @@
// We got the response for the PLDM request msg that was sent
if (!throttleTraces)
{
- log<level::INFO>(
- std::format(
- "pldmRspCallback: pldm_transport_recv_msg() rsp was {} bytes",
- responseMsgSize)
- .c_str());
+ lg2::info(
+ "pldmRspCallback: pldm_transport_recv_msg() rsp was {LEN} bytes",
+ "LEN", responseMsgSize);
}
if (pldmIface->pldmRspTimer.isEnabled())
@@ -985,10 +901,8 @@
auto response = reinterpret_cast<pldm_msg*>(responseMsgPtr.get());
if (response->payload[0] != PLDM_SUCCESS)
{
- log<level::ERR>(
- std::format("pldmRspCallback: payload[0] was not success: {}",
- response->payload[0])
- .c_str());
+ lg2::error("pldmRspCallback: payload[0] was not success: {STATUS}",
+ "STATUS", response->payload[0]);
pldmIface->pldmClose();
return -1;
}
@@ -1001,11 +915,9 @@
response, responseMsgSize, &compCode, &sensorCount, field);
if ((msgRc != PLDM_SUCCESS) || (compCode != PLDM_SUCCESS))
{
- log<level::ERR>(
- std::format(
- "pldmRspCallback: decode_get_state_sensor_readings failed with rc={} and compCode={}",
- msgRc, compCode)
- .c_str());
+ lg2::error(
+ "pldmRspCallback: decode_get_state_sensor_readings failed with rc={RC} and compCode={CC}",
+ "RC", msgRc, "CC", compCode);
pldmIface->pldmClose();
return -1;
}
@@ -1018,18 +930,15 @@
if (occSensorState == PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE)
{
- log<level::INFO>(
- std::format("pldmRspCallback: OCC{} is RUNNING", instance).c_str());
+ lg2::info("pldmRspCallback: OCC{INST} is RUNNING", "INST", instance);
pldmIface->occActiveCallBack(instance, true);
}
else if (occSensorState ==
PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT)
{
- log<level::ERR>(
- std::format(
- "pldmRspCallback: OCC{} has now STOPPED and system is in SAFE MODE",
- instance)
- .c_str());
+ lg2::error(
+ "pldmRspCallback: OCC{INST} has now STOPPED and system is in SAFE MODE",
+ "INST", instance);
// Setting safe mode true
pldmIface->safeModeCallBack(true);
@@ -1039,9 +948,8 @@
else if (occSensorState ==
PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED)
{
- log<level::INFO>(
- std::format("pldmRspCallback: OCC{} is not running", instance)
- .c_str());
+ lg2::info("pldmRspCallback: OCC{INST} is not running", "INST",
+ instance);
pldmIface->occActiveCallBack(instance, false);
}
else
@@ -1052,11 +960,10 @@
rspLength);
if (!throttleTraces)
{
- log<level::WARNING>(
- std::format(
- "pldmRspCallback: Unexpected State: {} - PLDM response ({} bytes) for OCC{}:",
- occSensorState, rspLength, instance)
- .c_str());
+ lg2::warning(
+ "pldmRspCallback: Unexpected State: {STATE} - PLDM response "
+ "({LEN} bytes) for OCC{INST}:",
+ "STATE", occSensorState, "LEN", rspLength, "INST", instance);
dump_hex(pldmResponse);
}
}
@@ -1070,8 +977,8 @@
{
if (!(revents & EPOLLIN))
{
- log<level::INFO>(
- std::format("pldmResetCallback - revents={:08X}", revents).c_str());
+ lg2::info("pldmResetCallback - revents={NUM}", "NUM", lg2::hex,
+ revents);
return -1;
}
@@ -1079,8 +986,7 @@
if (!pldmIface->pldmInstanceID)
{
- log<level::ERR>(
- "pldmResetCallback: No outstanding PLDM Instance ID found");
+ lg2::error("pldmResetCallback: No outstanding PLDM Instance ID found");
return -1;
}
@@ -1090,11 +996,9 @@
if (!throttleTraces)
{
- log<level::INFO>(
- std::format(
- "pldmResetCallback: calling pldm_transport_recv_msg() instance:{}",
- pldmIface->pldmInstanceID.value())
- .c_str());
+ lg2::info(
+ "pldmResetCallback: calling pldm_transport_recv_msg() instance:{ID}",
+ "ID", pldmIface->pldmInstanceID.value());
}
auto rc = pldm_transport_recv_msg(pldmIface->pldmTransport, &pldmTID,
(void**)&responseMsg, &responseMsgSize);
@@ -1103,13 +1007,12 @@
{
if (!throttleTraces)
{
- log<level::ERR>(
- std::format(
- "pldmResetCallback: pldm_transport_recv_msg failed with rc={}, errno={}/{}",
- static_cast<
- std::underlying_type_t<pldm_requester_error_codes>>(rc),
- lastErrno, strerror(lastErrno))
- .c_str());
+ lg2::error(
+ "pldmResetCallback: pldm_transport_recv_msg failed with rc={RC}, errno={ERR}/{STR}",
+ "RC",
+ static_cast<std::underlying_type_t<pldm_requester_error_codes>>(
+ rc),
+ "ERR", lastErrno, "STR", strerror(lastErrno));
}
return -1;
}
@@ -1117,11 +1020,9 @@
// We got the response for the PLDM request msg that was sent
if (!throttleTraces)
{
- log<level::INFO>(
- std::format(
- "pldmResetCallback: pldm_transport_recv_msg() rsp was {} bytes",
- responseMsgSize)
- .c_str());
+ lg2::info(
+ "pldmResetCallback: pldm_transport_recv_msg() rsp was {LEN} bytes",
+ "LEN", responseMsgSize);
}
if (pldmIface->pldmRspTimer.isEnabled())
@@ -1140,29 +1041,24 @@
auto response = reinterpret_cast<pldm_msg*>(responseMsgPtr.get());
if (response->payload[0] != PLDM_SUCCESS)
{
- log<level::ERR>(
- std::format(
- "pldmResetCallback: Reset FAILED ({}) - payload[0] was not success: {}",
- msgType, response->payload[0])
- .c_str());
+ lg2::error(
+ "pldmResetCallback: Reset FAILED ({MSG}) - payload[0] was not success: {STATUS}",
+ "MSG", msgType, "STATUS", response->payload[0]);
pldmIface->pldmClose();
if (msgType == MSG_OCC_RESET)
{
// Retry reset request
- log<level::ERR>(
- std::format(
- "pldmResetCallback: retrying reset request for OCC{}",
- resetInstance)
- .c_str());
+ lg2::error(
+ "pldmResetCallback: retrying reset request for OCC{INST}",
+ "INST", resetInstance);
pldmIface->resetOCC(resetInstance);
}
return -1;
}
else
{
- log<level::INFO>(
- "pldmResetCallback: Reset has been successfully started");
+ lg2::info("pldmResetCallback: Reset has been successfully started");
}
pldmIface->pldmClose();
@@ -1177,8 +1073,7 @@
{
if (!getPldmInstanceId())
{
- log<level::ERR>(
- "encodeGetStateSensorRequest: failed to getPldmInstanceId");
+ lg2::error("encodeGetStateSensorRequest: failed to getPldmInstanceId");
return std::vector<uint8_t>();
}
@@ -1192,11 +1087,9 @@
sensorId, sRearm, 0, msg);
if (msgRc != PLDM_SUCCESS)
{
- log<level::ERR>(
- std::format(
- "encodeGetStateSensorRequest: Failed to encode sensorId:0x{:08X} for OCC{} (rc={})",
- sensorId, instance, msgRc)
- .c_str());
+ lg2::error(
+ "encodeGetStateSensorRequest: Failed to encode sensorId:{ID} for OCC{INST} (rc={RC})",
+ "ID", lg2::hex, sensorId, "INST", instance, "RC", msgRc);
}
return request;
}
@@ -1209,11 +1102,9 @@
{
if (!throttleTraces && !tracedOnce)
{
- log<level::WARNING>(
- std::format(
- "checkActiveSensor: already waiting on OCC{} (fd={})",
- pldmResponseOcc, pldmFd)
- .c_str());
+ lg2::warning(
+ "checkActiveSensor: already waiting on OCC{INST} (fd={FD})",
+ "INST", pldmResponseOcc, "FD", pldmFd);
tracedOnce = true;
}
return;
@@ -1235,10 +1126,8 @@
// Query the OCC Active Sensor state for this instance
if (!throttleTraces)
{
- log<level::INFO>(
- std::format("checkActiveSensor: OCC{} / sensorID: 0x{:04X}",
- instance, entry->first)
- .c_str());
+ lg2::info("checkActiveSensor: OCC{INST} / sensorID: {ID}", "INST",
+ instance, "ID", lg2::hex, entry->first);
}
// Encode GetStateSensorReadings PLDM message
@@ -1256,12 +1145,10 @@
{
if (!throttleTraces)
{
- log<level::ERR>(
- std::format(
- "checkActiveSensor: Unable to find PLDM sensor for OCC{}",
- instance)
- .c_str());
- log<level::INFO>(
+ lg2::error(
+ "checkActiveSensor: Unable to find PLDM sensor for OCC{INST}",
+ "INST", instance);
+ lg2::info(
"checkActiveSensor: fetching STATE_SET_OPERATIONAL_RUNNING_STATUS");
}
fetchSensorInfo(PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
@@ -1275,11 +1162,11 @@
{
if (throttle)
{
- log<level::WARNING>("PLDM traces being throttled");
+ lg2::warning("PLDM traces being throttled");
}
else
{
- log<level::INFO>("PLDM traces no longer being throttled");
+ lg2::info("PLDM traces no longer being throttled");
}
throttleTraces = throttle;
}
diff --git a/powercap.cpp b/powercap.cpp
index a70d4e9..7ccc6d9 100644
--- a/powercap.cpp
+++ b/powercap.cpp
@@ -1,11 +1,10 @@
#include "occ_status.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <powercap.hpp>
#include <cassert>
#include <filesystem>
-#include <format>
namespace open_power
{
@@ -23,7 +22,6 @@
constexpr auto POWER_CAP_HARD_MIN = "MinPowerCapValue";
constexpr auto POWER_CAP_MAX = "MaxPowerCapValue";
-using namespace phosphor::logging;
namespace fs = std::filesystem;
void PowerCap::updatePcapBounds()
@@ -50,11 +48,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "updatePcapBounds: unable to find pcap_min_soft file: {} (errno={})",
- pcapBasePathname.c_str(), errno)
- .c_str());
+ lg2::error(
+ "updatePcapBounds: unable to find pcap_min_soft file: {FILE} (errno={ERR})",
+ "FILE", pcapBasePathname, "ERR", errno);
}
std::ifstream minFile(minName, std::ios::in);
@@ -67,11 +63,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "updatePcapBounds: unable to find cap_min file: {} (errno={})",
- pcapBasePathname.c_str(), errno)
- .c_str());
+ lg2::error(
+ "updatePcapBounds: unable to find cap_min file: {FILE} (errno={ERR})",
+ "FILE", pcapBasePathname, "ERR", errno);
}
std::ifstream maxFile(maxName, std::ios::in);
@@ -84,11 +78,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "updatePcapBounds: unable to find cap_max file: {} (errno={})",
- pcapBasePathname.c_str(), errno)
- .c_str());
+ lg2::error(
+ "updatePcapBounds: unable to find cap_max file: {FILE} (errno={ERR})",
+ "FILE", pcapBasePathname, "ERR", errno);
}
// Save the power cap bounds to dbus
@@ -106,11 +98,9 @@
if ((hwmonUserCap != 0) && (dbusUserCap != hwmonUserCap))
{
// User power cap is enabled, but does not match dbus
- log<level::ERR>(
- std::format(
- "updatePcapBounds: user powercap mismatch (hwmon:{}W, bdus:{}W) - using dbus",
- hwmonUserCap, dbusUserCap)
- .c_str());
+ lg2::error(
+ "updatePcapBounds: user powercap mismatch (hwmon:{HCAP}W, bdus:{DCAP}W) - using dbus",
+ "HCAP", hwmonUserCap, "DCAP", dbusUserCap);
auto occInput = getOccInput(dbusUserCap, pcapEnabled);
writeOcc(occInput);
}
@@ -123,19 +113,16 @@
{
newCap = capSoftMin;
}
- log<level::ERR>(
- std::format(
- "updatePcapBounds: user powercap {}W is outside bounds "
- "(soft min:{}, min:{}, max:{})",
- dbusUserCap, capSoftMin, capHardMin, capMax)
- .c_str());
+ lg2::error(
+ "updatePcapBounds: user powercap {CAP}W is outside bounds "
+ "(soft min:{SMIN}, min:{MIN}, max:{MAX})",
+ "CAP", dbusUserCap, "SMIN", capSoftMin, "MIN", capHardMin,
+ "MAX", capMax);
try
{
- log<level::INFO>(
- std::format(
- "updatePcapBounds: Updating user powercap from {} to {}W",
- hwmonUserCap, newCap)
- .c_str());
+ lg2::info(
+ "updatePcapBounds: Updating user powercap from {OLD} to {NEW}W",
+ "OLD", hwmonUserCap, "NEW", newCap);
utils::setProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_PROP,
newCap);
auto occInput = getOccInput(newCap, pcapEnabled);
@@ -143,11 +130,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format(
- "updatePcapBounds: Failed to update user powercap due to ",
- e.what())
- .c_str());
+ lg2::error(
+ "updatePcapBounds: Failed to update user powercap due to {ERR}",
+ "ERR", e.what());
}
}
}
@@ -178,9 +163,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to get PowerCap property",
- entry("ERROR=%s", e.what()),
- entry("PATH=%s", PCAP_PATH));
+ lg2::error("Failed to get PowerCap property: path={PATH}: {ERR}",
+ "PATH", PCAP_PATH, "ERR", e.what());
return 0;
}
@@ -198,9 +182,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to get PowerCapEnable property",
- entry("ERROR=%s", e.what()),
- entry("PATH=%s", PCAP_PATH));
+ lg2::error("Failed to get PowerCapEnable property: path={PATH}: {ERR}",
+ "PATH", PCAP_PATH, "ERR", e.what());
return false;
}
@@ -227,9 +210,8 @@
}
else
{
- log<level::ERR>(std::format("Power Cap base filename not found: {}",
- pcapBasePathname.c_str())
- .c_str());
+ lg2::error("Power Cap base filename not found: {FILE}", "FILE",
+ pcapBasePathname);
}
// return empty path
@@ -250,10 +232,8 @@
fs::path fileName = getPcapFilename(std::regex{"power\\d+_cap_user$"});
if (fileName.empty())
{
- log<level::ERR>(
- std::format("Could not find a power cap file to write to: {})",
- pcapBasePathname.c_str())
- .c_str());
+ lg2::error("Could not find a power cap file to write to: {FILE})",
+ "FILE", pcapBasePathname);
return;
}
@@ -265,17 +245,15 @@
std::ofstream file(fileName, std::ios::out);
if (file)
{
- log<level::INFO>(std::format("Writing {}uW to {}", pcapString.c_str(),
- fileName.c_str())
- .c_str());
+ lg2::info("Writing {CAP}uW to {FILE}", "CAP", pcapString, "FILE",
+ fileName);
file << pcapString;
file.close();
}
else
{
- log<level::ERR>(std::format("Failed writing {}uW to {} (errno={})",
- microWatts, fileName.c_str(), errno)
- .c_str());
+ lg2::error("Failed writing {CAP}uW to {FILE} (errno={ERR})", "CAP",
+ microWatts, "FILE", fileName, "ERR", errno);
}
return;
@@ -290,11 +268,9 @@
fs::path userCapName = getPcapFilename(std::regex{"power\\d+_cap_user$"});
if (userCapName.empty())
{
- log<level::ERR>(
- std::format(
- "readUserCapHwmon: Could not find a power cap file to read: {})",
- pcapBasePathname.c_str())
- .c_str());
+ lg2::error(
+ "readUserCapHwmon: Could not find a power cap file to read: {FILE})",
+ "FILE", pcapBasePathname);
return 0;
}
@@ -310,10 +286,8 @@
}
else
{
- log<level::ERR>(
- std::format("readUserCapHwmon: Failed reading {} (errno={})",
- userCapName.c_str(), errno)
- .c_str());
+ lg2::error("readUserCapHwmon: Failed reading {FILE} (errno={ERR})",
+ "FILE", userCapName, "ERR", errno);
}
return userCap;
@@ -352,11 +326,9 @@
else
{
// Ignore other properties
- log<level::DEBUG>(
- std::format(
- "pcapChanged: Unknown power cap property changed {} to {}",
- prop.c_str(), std::get<uint32_t>(value))
- .c_str());
+ lg2::debug(
+ "pcapChanged: Unknown power cap property changed {PROP} to {VAL}",
+ "PROP", prop, "VAL", std::get<uint32_t>(value));
}
}
@@ -365,32 +337,26 @@
readDbusPcapLimits(capSoftMin, capHardMin, capMax);
if (((pcap > 0) && (pcap < capSoftMin)) || ((pcap == 0) && (pcapEnabled)))
{
- log<level::ERR>(
- std::format(
- "pcapChanged: Power cap of {}W is lower than allowed (soft min:{}, min:{}) - using soft min",
- pcap, capSoftMin, capHardMin)
- .c_str());
+ lg2::error(
+ "pcapChanged: Power cap of {CAP}W is lower than allowed (soft min:{SMIN}, min:{MIN}) - using soft min",
+ "CAP", pcap, "SMIN", capSoftMin, "MIN", capHardMin);
pcap = capSoftMin;
utils::setProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_PROP, pcap);
}
else if (pcap > capMax)
{
- log<level::ERR>(
- std::format(
- "pcapChanged: Power cap of {}W is higher than allowed (max:{}) - using max",
- pcap, capSoftMin, capHardMin)
- .c_str());
+ lg2::error(
+ "pcapChanged: Power cap of {CAP}W is higher than allowed (max:{MAX}) - using max",
+ "CAP", pcap, "MAX", capMax);
pcap = capMax;
utils::setProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_PROP, pcap);
}
if (changeFound)
{
- log<level::INFO>(
- std::format(
- "Power Cap Property Change (cap={}W (input), enabled={})", pcap,
- pcapEnabled ? 'y' : 'n')
- .c_str());
+ lg2::info(
+ "Power Cap Property Change (cap={CAP}W (input), enabled={ENABLE})",
+ "CAP", pcap, "ENABLE", pcapEnabled);
// Determine desired action to write to occ
auto occInput = getOccInput(pcap, pcapEnabled);
@@ -414,11 +380,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format(
- "updateDbusPcapLimits: Failed to set SOFT PCAP to {}W due to {}",
- softMin, e.what())
- .c_str());
+ lg2::error(
+ "updateDbusPcapLimits: Failed to set SOFT PCAP to {MIN}W due to {ERR}",
+ "MIN", softMin, "ERR", e.what());
complete = false;
}
@@ -429,11 +393,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format(
- "updateDbusPcapLimits: Failed to set HARD PCAP to {}W due to {}",
- hardMin, e.what())
- .c_str());
+ lg2::error(
+ "updateDbusPcapLimits: Failed to set HARD PCAP to {MIN}W due to {ERR}",
+ "MIN", hardMin, "ERR", e.what());
complete = false;
}
@@ -443,11 +405,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format(
- "updateDbusPcapLimits: Failed to set MAX PCAP to {}W due to {}",
- max, e.what())
- .c_str());
+ lg2::error(
+ "updateDbusPcapLimits: Failed to set MAX PCAP to {MAX}W due to {ERR}",
+ "MAX", max, "ERR", e.what());
complete = false;
}
@@ -469,10 +429,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("readDbusPcapLimits: Failed to get SOFT PCAP due to {}",
- e.what())
- .c_str());
+ lg2::error("readDbusPcapLimits: Failed to get SOFT PCAP due to {ERR}",
+ "ERR", e.what());
softMin = 0;
complete = false;
}
@@ -485,10 +443,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("readDbusPcapLimits: Failed to get HARD PCAP due to {}",
- e.what())
- .c_str());
+ lg2::error("readDbusPcapLimits: Failed to get HARD PCAP due to {ERR}",
+ "ERR", e.what());
hardMin = 0;
complete = false;
}
@@ -500,10 +456,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("readDbusPcapLimits: Failed to get MAX PCAP due to {}",
- e.what())
- .c_str());
+ lg2::error("readDbusPcapLimits: Failed to get MAX PCAP due to {ERR}",
+ "ERR", e.what());
max = INT_MAX;
complete = false;
}
diff --git a/powermode.cpp b/powermode.cpp
index 2179bd8..51e95f5 100644
--- a/powermode.cpp
+++ b/powermode.cpp
@@ -3,14 +3,12 @@
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <format>
-
#ifdef POWERVM_CHECK
#include <com/ibm/Host/Target/server.hpp>
#endif
#include <org/open_power/OCC/Device/error.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Control/Power/Mode/server.hpp>
@@ -92,11 +90,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "PowerMode: Persisted power mode ({}/{}) is not valid. Reading system default mode",
- currentMode, oemModeData)
- .c_str());
+ lg2::error("PowerMode: Persisted power mode ({MODE}/{DATA}) is not "
+ "valid. Reading system default mode",
+ "MODE", currentMode, "DATA", oemModeData);
persistedData.invalidateMode();
// Read default power mode
initPersistentData();
@@ -108,7 +104,7 @@
{
if (!ipsObject)
{
- log<level::INFO>("createIpsObject: Creating IPS object");
+ lg2::info("createIpsObject: Creating IPS object");
ipsObject =
std::make_unique<IpsInterface>(utils::getBus(), ipsObjectPath);
@@ -136,7 +132,7 @@
// Stop watching for IPS state changes.
removeIpsWatch();
- log<level::INFO>("removeIpsObject: Deleting IPS object");
+ lg2::info("removeIpsObject: Deleting IPS object");
ipsObject.reset(nullptr);
}
needToSendIpsData = false;
@@ -149,11 +145,9 @@
{
if (masterOccPath != path)
{
- log<level::ERR>(
- std::format(
- "PowerMode::setMasterOcc: Master changed (was OCC{}, {})",
- occInstance, masterOccPath)
- .c_str());
+ lg2::error(
+ "PowerMode::setMasterOcc: Master changed (was OCC{INST}, {PATH})",
+ "INST", occInstance, "PATH", masterOccPath);
if (occCmd)
{
occCmd.reset();
@@ -162,9 +156,8 @@
}
path = masterOccPath;
occInstance = path.back() - '0';
- log<level::DEBUG>(std::format("PowerMode::setMasterOcc(OCC{}, {})",
- occInstance, path.c_str())
- .c_str());
+ lg2::debug("PowerMode::setMasterOcc(OCC{INST}, {PATH})", "INST",
+ occInstance, "PATH", path);
if (!occCmd)
{
occCmd = std::make_unique<open_power::occ::OccCommand>(
@@ -176,7 +169,7 @@
// Set the state of power mode lock. Writing persistent data via dbus method.
bool PowerMode::powerModeLock()
{
- log<level::INFO>("PowerMode::powerModeLock: locking mode change");
+ lg2::info("PowerMode::powerModeLock: locking mode change");
persistedData.updateModeLock(true); // write persistent data
return true;
}
@@ -185,9 +178,8 @@
bool PowerMode::powerModeLockStatus()
{
bool status = persistedData.getModeLock(); // read persistent data
- log<level::INFO>(std::format("PowerMode::powerModeLockStatus: {}",
- status ? "locked" : "unlocked")
- .c_str());
+ lg2::info("PowerMode::powerModeLockStatus: {STATUS}", "STATUS",
+ status ? "locked" : "unlocked");
return status;
}
@@ -196,7 +188,7 @@
{
if (persistedData.getModeLock())
{
- log<level::INFO>("PowerMode::setMode: mode change blocked");
+ lg2::info("PowerMode::setMode: mode change blocked");
return false;
}
@@ -248,7 +240,7 @@
return SysPwrMode::BALANCED_PERF;
}
- log<level::WARNING>("getInternalMode: Invalid PowerMode specified");
+ lg2::warning("getInternalMode: Invalid PowerMode specified");
return SysPwrMode::NO_CHANGE;
}
@@ -291,10 +283,9 @@
}
else
{
- log<level::ERR>(
- std::format("convertStringToMode: Invalid Power Mode: {} ({})",
- shortMode, e.what())
- .c_str());
+ lg2::error(
+ "convertStringToMode: Invalid Power Mode: {MODE} ({DATA})",
+ "MODE", shortMode, "DATA", e.what());
}
}
return newMode;
@@ -327,8 +318,7 @@
powerVmTarget = true;
}
- log<level::DEBUG>(
- std::format("isPowerVM returning {}", powerVmTarget).c_str());
+ lg2::debug("isPowerVM returning {VAL}", "VAL", powerVmTarget);
#endif
return powerVmTarget;
@@ -346,10 +336,8 @@
// Unable to read defaults
return false;
}
- log<level::INFO>(
- std::format("PowerMode::initPersistentData: Using default mode: {}",
- currentMode)
- .c_str());
+ lg2::info("PowerMode::initPersistentData: Using default mode: {MODE}",
+ "MODE", currentMode);
// Save default mode as current mode
persistedData.updateMode(currentMode, 0);
@@ -392,11 +380,9 @@
{
if (!isValidMode(newMode))
{
- log<level::ERR>(
- std::format(
- "PowerMode::updateDbusMode - Requested power mode not supported: {}",
- newMode)
- .c_str());
+ lg2::error(
+ "PowerMode::updateDbusMode - Requested power mode not supported: {MODE}",
+ "MODE", newMode);
return false;
}
@@ -473,15 +459,14 @@
if (!masterActive || !masterOccSet)
{
// Nothing to do until OCC goes active
- log<level::DEBUG>(
- "PowerMode::sendModeChange: OCC master not active");
+ lg2::debug("PowerMode::sendModeChange: OCC master not active");
return CmdStatus::SUCCESS;
}
if (!isPowerVM())
{
// Mode change is only supported on PowerVM systems
- log<level::DEBUG>(
+ lg2::debug(
"PowerMode::sendModeChange: MODE CHANGE does not get sent on non-PowerVM systems");
return CmdStatus::SUCCESS;
}
@@ -497,11 +482,10 @@
cmd.push_back(oemModeData >> 8); // Mode Data (Freq Point)
cmd.push_back(oemModeData & 0xFF); //
cmd.push_back(0x00); // reserved
- log<level::INFO>(
- std::format(
- "PowerMode::sendModeChange: SET_MODE({},{}) command to OCC{} ({} bytes)",
- newMode, oemModeData, occInstance, cmd.size())
- .c_str());
+ lg2::info(
+ "PowerMode::sendModeChange: SET_MODE({MODE},{DATA}) command to OCC{INST} ({LEN} bytes)",
+ "MODE", uint8_t(newMode), "DATA", oemModeData, "INST", occInstance,
+ "LEN", cmd.size());
status = occCmd->send(cmd, rsp);
if (status == CmdStatus::SUCCESS)
{
@@ -518,18 +502,16 @@
}
else
{
- log<level::ERR>(
- std::format(
- "PowerMode::sendModeChange: SET MODE failed with status 0x{:02X}",
- rsp[2])
- .c_str());
+ lg2::error(
+ "PowerMode::sendModeChange: SET MODE failed with status {STATUS}",
+ "STATUS", lg2::hex, rsp[2]);
dump_hex(rsp);
status = CmdStatus::FAILURE;
}
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::sendModeChange: INVALID SET MODE response");
dump_hex(rsp);
status = CmdStatus::FAILURE;
@@ -537,20 +519,16 @@
}
else
{
- log<level::ERR>(
- std::format(
- "PowerMode::sendModeChange: SET_MODE FAILED with status={}",
- status)
- .c_str());
+ lg2::error(
+ "PowerMode::sendModeChange: SET_MODE FAILED with status={STATUS}",
+ "STATUS", lg2::hex, uint8_t(status));
}
}
else
{
- log<level::ERR>(
- std::format(
- "PowerMode::sendModeChange: Unable to set power mode to {}",
- newMode)
- .c_str());
+ lg2::error(
+ "PowerMode::sendModeChange: Unable to set power mode to {MODE}",
+ "MODE", newMode);
status = CmdStatus::FAILURE;
}
@@ -574,7 +552,7 @@
if (!ipsObject)
{
- log<level::WARNING>(
+ lg2::warning(
"ipsChanged: Idle Power Saver can not be modified in an ECO power mode");
return;
}
@@ -584,18 +562,16 @@
if (ipsEntry != ipsProperties.end())
{
ipsEnabled = std::get<bool>(ipsEntry->second);
- log<level::INFO>(
- std::format("Idle Power Saver change: Enabled={}", ipsEnabled)
- .c_str());
+ lg2::info("Idle Power Saver change: Enabled={STAT}", "STAT",
+ ipsEnabled);
parmsChanged = true;
}
ipsEntry = ipsProperties.find(IPS_ENTER_UTIL);
if (ipsEntry != ipsProperties.end())
{
enterUtil = std::get<uint8_t>(ipsEntry->second);
- log<level::INFO>(
- std::format("Idle Power Saver change: Enter Util={}%", enterUtil)
- .c_str());
+ lg2::info("Idle Power Saver change: Enter Util={UTIL}%", "UTIL",
+ enterUtil);
parmsChanged = true;
}
ipsEntry = ipsProperties.find(IPS_ENTER_TIME);
@@ -604,18 +580,16 @@
std::chrono::milliseconds ms(std::get<uint64_t>(ipsEntry->second));
enterTime =
std::chrono::duration_cast<std::chrono::seconds>(ms).count();
- log<level::INFO>(
- std::format("Idle Power Saver change: Enter Time={}sec", enterTime)
- .c_str());
+ lg2::info("Idle Power Saver change: Enter Time={TIME}sec", "TIME",
+ enterTime);
parmsChanged = true;
}
ipsEntry = ipsProperties.find(IPS_EXIT_UTIL);
if (ipsEntry != ipsProperties.end())
{
exitUtil = std::get<uint8_t>(ipsEntry->second);
- log<level::INFO>(
- std::format("Idle Power Saver change: Exit Util={}%", exitUtil)
- .c_str());
+ lg2::info("Idle Power Saver change: Exit Util={UTIL}%", "UTIL",
+ exitUtil);
parmsChanged = true;
}
ipsEntry = ipsProperties.find(IPS_EXIT_TIME);
@@ -623,9 +597,8 @@
{
std::chrono::milliseconds ms(std::get<uint64_t>(ipsEntry->second));
exitTime = std::chrono::duration_cast<std::chrono::seconds>(ms).count();
- log<level::INFO>(
- std::format("Idle Power Saver change: Exit Time={}sec", exitTime)
- .c_str());
+ lg2::info("Idle Power Saver change: Exit Time={TIME}sec", "TIME",
+ exitTime);
parmsChanged = true;
}
@@ -635,7 +608,7 @@
{
// Setting the exitUtil to 0 will force restoring the default IPS
// parmeters (0 is not valid exit utilization)
- log<level::INFO>(
+ lg2::info(
"Idle Power Saver Exit Utilization is 0%. Restoring default parameters");
// Read the default IPS parameters, write persistent file and update
// DBus
@@ -685,11 +658,9 @@
if (enterUtil > exitUtil)
{
- log<level::ERR>(
- std::format(
- "ERROR: Idle Power Saver Enter Utilization ({}%) is > Exit Utilization ({}%) - using Exit for both",
- enterUtil, exitUtil)
- .c_str());
+ lg2::error(
+ "ERROR: Idle Power Saver Enter Utilization ({ENTER}%) is > Exit Utilization ({EXIT}%) - using Exit for both",
+ "ENTER", enterUtil, "EXIT", exitUtil);
enterUtil = exitUtil;
}
@@ -715,7 +686,7 @@
}
else
{
- log<level::WARNING>("updateDbusIPS: No IPS object was found");
+ lg2::warning("updateDbusIPS: No IPS object was found");
}
return true;
@@ -733,7 +704,7 @@
if (!isPowerVM())
{
// Idle Power Saver data is only supported on PowerVM systems
- log<level::DEBUG>(
+ lg2::debug(
"PowerMode::sendIpsData: SET_CFG_DATA[IPS] does not get sent on non-PowerVM systems");
return CmdStatus::SUCCESS;
}
@@ -741,7 +712,7 @@
if (!ipsObject)
{
// Idle Power Saver data is not available in Eco Modes
- log<level::INFO>(
+ lg2::info(
"PowerMode::sendIpsData: Skipping IPS data due to being in an ECO Power Mode");
return CmdStatus::SUCCESS;
}
@@ -751,11 +722,10 @@
uint16_t enterTime, exitTime;
getIPSParms(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime);
- log<level::INFO>(
- std::format(
- "Idle Power Saver Parameters: enabled:{}, enter:{}%/{}s, exit:{}%/{}s",
- ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)
- .c_str());
+ lg2::info(
+ "Idle Power Saver Parameters: enabled:{ENABLE}, enter:{EUTIL}%/{ETIME}s, exit:{XUTIL}%/{XTIME}s",
+ "ENABLE", ipsEnabled, "EUTIL", enterUtil, "ETIME", enterTime, "XUTIL",
+ exitUtil, "XTIME", exitTime);
std::vector<std::uint8_t> cmd, rsp;
cmd.reserve(12);
@@ -771,10 +741,9 @@
cmd.push_back(exitTime >> 8); // Exit Delay Time
cmd.push_back(exitTime & 0xFF); //
cmd.push_back(exitUtil); // Exit Utilization
- log<level::INFO>(std::format("PowerMode::sendIpsData: SET_CFG_DATA[IPS] "
- "command to OCC{} ({} bytes)",
- occInstance, cmd.size())
- .c_str());
+ lg2::info("PowerMode::sendIpsData: SET_CFG_DATA[IPS] "
+ "command to OCC{INST} ({LEN} bytes)",
+ "INST", occInstance, "LEN", cmd.size());
CmdStatus status = occCmd->send(cmd, rsp);
if (status == CmdStatus::SUCCESS)
{
@@ -786,18 +755,16 @@
}
else
{
- log<level::ERR>(
- std::format(
- "PowerMode::sendIpsData: SET_CFG_DATA[IPS] failed with status 0x{:02X}",
- rsp[2])
- .c_str());
+ lg2::error(
+ "PowerMode::sendIpsData: SET_CFG_DATA[IPS] failed with status {STATUS}",
+ "STATUS", lg2::hex, rsp[2]);
dump_hex(rsp);
status = CmdStatus::FAILURE;
}
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::sendIpsData: INVALID SET_CFG_DATA[IPS] response");
dump_hex(rsp);
status = CmdStatus::FAILURE;
@@ -805,11 +772,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "PowerMode::sendIpsData: SET_CFG_DATA[IPS] with status={}",
- status)
- .c_str());
+ lg2::error(
+ "PowerMode::sendIpsData: SET_CFG_DATA[IPS] with status={STATUS}",
+ "STATUS", lg2::hex, uint8_t(status));
}
return status;
@@ -820,22 +785,19 @@
{
if (modeData.modeInitialized)
{
- log<level::INFO>(
- std::format(
- "OccPersistData: Mode: 0x{:02X}, OEM Mode Data: {} (0x{:04X} Locked{})",
- modeData.mode, modeData.oemModeData, modeData.oemModeData,
- modeData.modeLocked)
- .c_str());
+ lg2::info(
+ "OccPersistData: Mode: {MODE}, OEM Mode Data: {DATA} ({DATAHEX} Locked{LOCK})",
+ "MODE", lg2::hex, uint8_t(modeData.mode), "DATA",
+ modeData.oemModeData, "DATAHEX", lg2::hex, modeData.oemModeData,
+ "LOCK", modeData.modeLocked);
}
if (modeData.ipsInitialized)
{
- log<level::INFO>(
- std::format(
- "OccPersistData: IPS enabled:{}, enter:{}%/{}s, exit:{}%/{}s",
- modeData.ipsEnabled, modeData.ipsEnterUtil,
- modeData.ipsEnterTime, modeData.ipsExitUtil,
- modeData.ipsExitTime)
- .c_str());
+ lg2::info(
+ "OccPersistData: IPS enabled:{ENABLE}, enter:{EUTIL}%/{ETIME}s, exit:{XUTIL}%/{XTIME}s",
+ "ENABLE", modeData.ipsEnabled, "EUTIL", modeData.ipsEnterUtil,
+ "ETIME", modeData.ipsEnterTime, "XUTIL", modeData.ipsExitUtil,
+ "XTIME", modeData.ipsExitTime);
}
}
@@ -850,11 +812,9 @@
std::filesystem::create_directory(opath.parent_path());
}
- log<level::DEBUG>(
- std::format(
- "OccPersistData::save: Writing Power Mode persisted data to {}",
- opath.c_str())
- .c_str());
+ lg2::debug(
+ "OccPersistData::save: Writing Power Mode persisted data to {FILE}",
+ "FILE", opath);
// print();
std::ofstream stream{opath.c_str()};
@@ -876,11 +836,9 @@
return;
}
- log<level::DEBUG>(
- std::format(
- "OccPersistData::load: Reading Power Mode persisted data from {}",
- ipath.c_str())
- .c_str());
+ lg2::debug(
+ "OccPersistData::load: Reading Power Mode persisted data from {FILE}",
+ "FILE", ipath);
try
{
std::ifstream stream{ipath.c_str()};
@@ -890,10 +848,8 @@
catch (const std::exception& e)
{
auto error = errno;
- log<level::ERR>(
- std::format("OccPersistData::load: failed to read {}, errno={}",
- ipath.c_str(), error)
- .c_str());
+ lg2::error("OccPersistData::load: failed to read {FILE}, errno={ERR}",
+ "FILE", ipath, "ERR", error);
modeData.modeInitialized = false;
modeData.ipsInitialized = false;
}
@@ -916,11 +872,9 @@
persistedData.getMode(pMode, oemModeData);
if (!isValidMode(pMode))
{
- log<level::ERR>(
- std::format(
- "defaultsReady: Persisted power mode ({}/{}) is not valid. Reading system default mode",
- pMode, oemModeData)
- .c_str());
+ lg2::error(
+ "defaultsReady: Persisted power mode ({MODE}/{DATA}) is not valid. Reading system default mode",
+ "MODE", pMode, "DATA", oemModeData);
persistedData.invalidateMode();
}
}
@@ -928,12 +882,10 @@
// If persistent data exists, then don't need to read defaults
if ((!persistedData.modeAvailable()) || (!persistedData.ipsAvailable()))
{
- log<level::INFO>(
- std::format(
- "Default PowerModeProperties are now available (persistent modeAvail={}, ipsAvail={})",
- persistedData.modeAvailable() ? 'y' : 'n',
- persistedData.ipsAvailable() ? 'y' : 'n')
- .c_str());
+ lg2::info(
+ "Default PowerModeProperties are now available (persistent modeAvail={MAVAIL}, ipsAvail={IAVAIL})",
+ "MAVAIL", persistedData.modeAvailable(), "IAVAIL",
+ persistedData.ipsAvailable());
// Read default power mode defaults and update DBus
initPersistentData();
@@ -964,10 +916,9 @@
defaultMode = powermode::convertStringToMode(fullModeString);
if (!VALID_POWER_MODE_SETTING(defaultMode))
{
- log<level::ERR>(std::format("PowerMode::getDefaultMode: Invalid "
- "default power mode found: {}",
- defaultMode)
- .c_str());
+ lg2::error("PowerMode::getDefaultMode: Invalid "
+ "default power mode found: {MODE}",
+ "MODE", defaultMode);
// If default was read but not valid, use Max Performance
defaultMode = SysPwrMode::MAX_PERF;
return true;
@@ -975,9 +926,7 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Unable to read Default Power Mode: {}", e.what())
- .c_str());
+ lg2::error("Unable to read Default Power Mode: {ERR}", "ERR", e.what());
return false;
}
@@ -1015,11 +964,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format(
- "Unable to read Default Idle Power Saver parameters so it will be disabled: {}",
- e.what())
- .c_str());
+ lg2::error(
+ "Unable to read Default Idle Power Saver parameters so it will be disabled: {ERR}",
+ "ERR", e.what());
return false;
}
@@ -1030,7 +977,7 @@
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::getDefaultIPSParms could not find property: IdlePowerSaverEnabled");
}
@@ -1041,7 +988,7 @@
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::getDefaultIPSParms could not find property: EnterUtilizationPercent");
}
@@ -1052,7 +999,7 @@
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::getDefaultIPSParms could not find property: EnterUtilizationDwellTime");
}
@@ -1063,7 +1010,7 @@
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::getDefaultIPSParms could not find property: ExitUtilizationPercent");
}
@@ -1074,17 +1021,15 @@
}
else
{
- log<level::ERR>(
+ lg2::error(
"PowerMode::getDefaultIPSParms could not find property: ExitUtilizationDwellTime");
}
if (enterUtil > exitUtil)
{
- log<level::ERR>(
- std::format(
- "ERROR: Default Idle Power Saver Enter Utilization ({}%) is > Exit Utilization ({}%) - using Exit for both",
- enterUtil, exitUtil)
- .c_str());
+ lg2::error(
+ "ERROR: Default Idle Power Saver Enter Utilization ({ENTER}%) is > Exit Utilization ({EXIT}%) - using Exit for both",
+ "ENTER", enterUtil, "EXIT", exitUtil);
enterUtil = exitUtil;
}
@@ -1105,11 +1050,11 @@
// Unable to read defaults
return false;
}
- log<level::INFO>(
- std::format(
- "PowerMode::useDefaultIPSParms: Using default IPS parms: Enabled: {}, EnterUtil: {}%, EnterTime: {}s, ExitUtil: {}%, ExitTime: {}s",
- ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)
- .c_str());
+ lg2::info("PowerMode::useDefaultIPSParms: Using default IPS parms: "
+ "Enabled: {ENABLE}, EnterUtil: {EUTIL}%, EnterTime: {ETIME}s, "
+ "ExitUtil: {XUTIL}%, ExitTime: {XTIME}s",
+ "ENABLE", ipsEnabled, "EUTIL", enterUtil, "ETIME", enterTime,
+ "XUTIL", exitUtil, "XTIME", exitTime);
// Save IPS parms to the persistent file
persistedData.updateIPS(ipsEnabled, enterUtil, enterTime, exitUtil,
@@ -1127,10 +1072,9 @@
const int open_errno = errno;
if (fd < 0)
{
- log<level::ERR>(
- std::format("openIpsFile Error({})={} : File={}", open_errno,
- strerror(open_errno), ipsStatusFile.c_str())
- .c_str());
+ lg2::error("openIpsFile Error({ERR})={STR} : File={FILE}", "ERR",
+ open_errno, "STR", strerror(open_errno), "FILE",
+ ipsStatusFile);
close(fd);
@@ -1201,9 +1145,8 @@
ipsStatusCallBack, this);
if (r < 0)
{
- log<level::ERR>(std::format("sd_event_add_io: Error({})={} : File={}",
- r, strerror(-r), ipsStatusFile.c_str())
- .c_str());
+ lg2::error("sd_event_add_io: Error({ERR})={STR} : File={FILE}", "ERR",
+ r, "STR", strerror(-r), "FILE", ipsStatusFile);
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -1261,11 +1204,10 @@
{
removeIpsWatch();
- log<level::ERR>(
- std::format("IPS state Read Error({})={} : File={} : len={}",
- readErrno, strerror(readErrno),
- ipsStatusFile.c_str(), len)
- .c_str());
+ lg2::error(
+ "IPS state Read Error({ERR})={STR} : File={FILE} : len={LEN}",
+ "ERR", readErrno, "STR", strerror(readErrno), "FILE",
+ ipsStatusFile, "LEN", len);
report<ReadFailure>(
phosphor::logging::org::open_power::OCC::Device::ReadFailure::
@@ -1301,10 +1243,9 @@
// If the Retry did not get to "watching = true" we already have an
// error log, just post trace.
- log<level::ERR>(
- std::format("Retry on File seek Error({})={} : File={}", open_errno,
- strerror(open_errno), ipsStatusFile.c_str())
- .c_str());
+ lg2::error("Retry on File seek Error({ERR})={STR} : File={FILE}", "ERR",
+ open_errno, "STR", strerror(open_errno), "FILE",
+ ipsStatusFile);
// NOTE: this will leave the system not reporting IPS active state to
// Fan Controls, Until an APP reload, or IPL and we will attempt again.
@@ -1318,7 +1259,7 @@
{
if (persistedData.getModeLock())
{
- log<level::INFO>("PowerMode::powerMode: mode property change blocked");
+ lg2::info("PowerMode::powerMode: mode property change blocked");
elog<NotAllowed>(xyz::openbmc_project::Common::NotAllowed::REASON(
"mode change not allowed due to lock"));
}
@@ -1336,10 +1277,8 @@
// Update persisted data with new mode
persistedData.updateMode(newMode, 0);
- log<level::INFO>(
- std::format("DBus PowerMode Changed: {}",
- convertPowerModeToString(requestedMode))
- .c_str());
+ lg2::info("DBus PowerMode Changed: {MODE}", "MODE",
+ convertPowerModeToString(requestedMode));
// Send mode change to OCC
sendModeChange();
@@ -1347,11 +1286,9 @@
else
{
// Not Allowed
- log<level::ERR>(
- std::format(
- "PowerMode change not allowed. {} is not in AllowedPowerModes",
- convertPowerModeToString(requestedMode))
- .c_str());
+ lg2::error(
+ "PowerMode change not allowed. {MODE} is not in AllowedPowerModes",
+ "MODE", convertPowerModeToString(requestedMode));
elog<NotAllowed>(
xyz::openbmc_project::Common::NotAllowed::REASON(
"PowerMode value not allowed"));
@@ -1363,11 +1300,9 @@
using InvalidArgument =
sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
using Argument = xyz::openbmc_project::Common::InvalidArgument;
- log<level::ERR>(
- std::format(
- "PowerMode not valid. {} is not in AllowedPowerModes",
- convertPowerModeToString(requestedMode))
- .c_str());
+ lg2::error(
+ "PowerMode not valid. {MODE} is not in AllowedPowerModes",
+ "MODE", convertPowerModeToString(requestedMode));
elog<InvalidArgument>(Argument::ARGUMENT_NAME("PowerMode"),
Argument::ARGUMENT_VALUE("INVALID MODE"));
}
@@ -1382,10 +1317,8 @@
*/
void PowerMode::updateDbusSafeMode(const bool safeModeReq)
{
- log<level::DEBUG>(
- std::format("PowerMode:updateDbusSafeMode: Update dbus state ({})",
- safeModeReq)
- .c_str());
+ lg2::debug("PowerMode:updateDbusSafeMode: Update dbus state ({STATE})",
+ "STATE", safeModeReq);
// Note; this function checks and only updates if different.
Mode::safeMode(safeModeReq);
@@ -1415,9 +1348,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Unable to read PowerModeProperties: {}", e.what())
- .c_str());
+ lg2::error("Unable to read PowerModeProperties: {ERR}", "ERR",
+ e.what());
return false;
}
@@ -1426,9 +1358,8 @@
if (ecoSupport != powerModeProperties.end())
{
ecoModeSupport = std::get<bool>(ecoSupport->second);
- log<level::INFO>(std::format("getSupportedModes(): ecoModeSupport: {}",
- ecoModeSupport)
- .c_str());
+ lg2::info("getSupportedModes(): ecoModeSupport: {SUPPORT}", "SUPPORT",
+ ecoModeSupport);
}
// Determine what customer modes are supported
@@ -1443,8 +1374,7 @@
// Ensure mode is valid
const std::string fullModeString =
PMODE_INTERFACE + ".PowerMode."s + mode;
- log<level::INFO>(
- std::format("getSupportedModes(): {}", mode).c_str());
+ lg2::info("getSupportedModes(): {MODE}", "MODE", mode);
SysPwrMode modeValue =
powermode::convertStringToMode(fullModeString);
if (VALID_POWER_MODE_SETTING(modeValue))
@@ -1464,11 +1394,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "getSupportedModes(): Ignoring unsupported customer mode {}",
- mode)
- .c_str());
+ lg2::error(
+ "getSupportedModes(): Ignoring unsupported customer mode {MODE}",
+ "MODE", mode);
}
}
}
@@ -1504,11 +1432,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "getSupportedModes(): Ignoring unsupported OEM mode {}",
- mode)
- .c_str());
+ lg2::error(
+ "getSupportedModes(): Ignoring unsupported OEM mode {MODE}",
+ "MODE", mode);
}
}
}
diff --git a/utils.cpp b/utils.cpp
index bb9743b..efb7abd 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -4,12 +4,12 @@
#include <unistd.h>
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
#include <xyz/openbmc_project/State/Host/server.hpp>
-#include <format>
#include <string>
namespace open_power
{
@@ -42,9 +42,8 @@
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- log<level::ERR>("ERROR reading mapper response",
- entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ lg2::error("ERROR reading mapper response: path={PATH}, I/F={INTF}",
+ "PATH", path, "INTF", interface);
elog<InternalFailure>();
}
@@ -106,19 +105,15 @@
auto reply = bus.call(method);
if (reply.is_method_error())
{
- log<level::ERR>(
- std::format("util::setProperty: Failed to set property {}",
- propertyName)
- .c_str());
+ lg2::error("util::setProperty: Failed to set property {PROP}",
+ "PROP", propertyName);
}
}
catch (const std::exception& e)
{
auto error = errno;
- log<level::ERR>(
- std::format("setProperty: failed to Set {}, errno={}, what={}",
- propertyName.c_str(), error, e.what())
- .c_str());
+ lg2::error("setProperty: failed to Set {PROP}, errno={ERR}, what={MSG}",
+ "PROP", propertyName, "ERR", error, "PROP", e.what());
}
}
@@ -159,11 +154,9 @@
mapperResponseMsg.read(rspObjects);
if (rspObjects.empty())
{
- log<level::ERR>(
- std::format(
- "util::getServiceUsingSubTree: Failed getSubTree({},0,{})",
- path.c_str(), interface)
- .c_str());
+ lg2::error(
+ "util::getServiceUsingSubTree: Failed getSubTree({PATH},0,{INTF})",
+ "PATH", path, "INTF", interface);
}
else
{
@@ -174,11 +167,9 @@
}
else
{
- log<level::ERR>(
- std::format(
- "getServiceUsingSubTree: service not found for interface {} (path={})",
- interface, path.c_str())
- .c_str());
+ lg2::error(
+ "getServiceUsingSubTree: service not found for interface {INTF} (path={PATH})",
+ "INTF", interface, "PATH", path);
}
}
@@ -214,19 +205,18 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(std::format("D-Bus call exception, OBJPATH({}), "
- "INTERFACE({}), PROPERTY({}) EXCEPTION({})",
- objPath, intf, state, e.what())
- .c_str());
+ lg2::error("D-Bus call exception, OBJPATH({PATH}), "
+ "INTERFACE({INTF}), PROPERTY({PROP}) EXCEPTION({ERR})",
+ "PATH", objPath, "INTF", intf, "PROP", state, "ERR",
+ e.what());
throw std::runtime_error("Failed to get host state property");
}
catch (const std::bad_variant_access& e)
{
- log<level::ERR>(
- std::format("Exception raised while read host state({}) property "
- "value, OBJPATH({}), INTERFACE({}), EXCEPTION({})",
- state, objPath, intf, e.what())
- .c_str());
+ lg2::error(
+ "Exception raised while read host state({STATE}) property "
+ "value, OBJPATH({PATH}), INTERFACE({INTF}), EXCEPTION({ERR})",
+ "STATE", state, "PATH", objPath, "INTF", intf, "ERR", e.what());
throw std::runtime_error("Failed to get host state property");
}