Move phosphor-power-supply to lg2
Update the logging API used for files in phosphor-power-supply
from the older phosphor::logging::log style of journal traces
to the newer lg2::log style.
Tested:
* Verified journal traces worked correctly in simulation.
* Verified that formatting and key-value pairs for the
messages were correct via the journalctl command output.
Change-Id: Ib4c031be1e43a1726f8d22215fce2d4ccc330cfa
Signed-off-by: Anwaar Hadi <anwaar.hadi@ibm.com>
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index 68b2c7c..331b4ba 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -5,6 +5,7 @@
#include "types.hpp"
#include "util.hpp"
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/Device/error.hpp>
#include <chrono> // sleep_for()
@@ -44,8 +45,8 @@
shortName = findShortName(inventoryPath);
- log<level::DEBUG>(
- std::format("{} gpioLineName: {}", shortName, gpioLineName).c_str());
+ lg2::debug("{SHORT_NAME} gpioLineName: {GPIO_LINE_NAME}", "SHORT_NAME",
+ shortName, "GPIO_LINE_NAME", gpioLineName);
presenceGPIO = createGPIO(gpioLineName);
std::ostringstream ss;
@@ -104,7 +105,7 @@
// This case should not happen, if no device driver name return.
if (driverName.empty())
{
- log<level::INFO>("No device driver name found");
+ lg2::info("No device driver name found");
return;
}
if (bindPath.string().find(driverName) != std::string::npos)
@@ -127,17 +128,13 @@
if (present)
{
std::this_thread::sleep_for(std::chrono::milliseconds(bindDelay));
- log<level::INFO>(
- std::format("Binding device driver. path: {} device: {}",
- path.string(), bindDevice)
- .c_str());
+ lg2::info("Binding device driver. path: {PATH} device: {BIND_DEVICE}",
+ "PATH", path, "BIND_DEVICE", bindDevice);
}
else
{
- log<level::INFO>(
- std::format("Unbinding device driver. path: {} device: {}",
- path.string(), bindDevice)
- .c_str());
+ lg2::info("Unbinding device driver. path: {PATH} device: {BIND_DEVICE}",
+ "PATH", path, "BIND_DEVICE", bindDevice);
}
std::ofstream file;
@@ -155,9 +152,8 @@
{
auto err = errno;
- log<level::ERR>(
- std::format("Failed binding or unbinding device. errno={}", err)
- .c_str());
+ lg2::error("Failed binding or unbinding device. errno={ERRNO}", "ERRNO",
+ err);
}
}
@@ -171,10 +167,8 @@
{
// Relying on property change or interface added to retry.
// Log an informational trace to the journal.
- log<level::INFO>(
- std::format("D-Bus property {} access failure exception",
- inventoryPath)
- .c_str());
+ lg2::info("D-Bus property {INVENTORY_PATH} access failure exception",
+ "INVENTORY_PATH", inventoryPath);
}
}
@@ -195,16 +189,15 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("presenceGPIO read fail: {}", e.what()).c_str());
+ lg2::error("presenceGPIO read fail: {ERROR}", "ERROR", e);
throw;
}
if (presentOld != present)
{
- log<level::DEBUG>(std::format("{} presentOld: {} present: {}",
- shortName, presentOld, present)
- .c_str());
+ lg2::debug("{SHORT_NAME} presentOld: {PRESENT_OLD} present: {PRESENT}",
+ "SHORT_NAME", shortName, "PRESENT_OLD", presentOld,
+ "PRESENT", present);
auto invpath = inventoryPath.substr(strlen(INVENTORY_OBJ_PATH));
@@ -248,11 +241,12 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format("{} CML fault: STATUS_WORD = {:#06x}, "
- "STATUS_CML = {:#02x}",
- shortName, statusWord, statusCML)
- .c_str());
+ lg2::error(
+ "{SHORT_NAME} CML fault: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_CML = {STATUS_CML}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord, "STATUS_CML",
+ lg2::hex | lg2::field8, statusCML);
}
cmlFault++;
}
@@ -271,12 +265,14 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format("{} INPUT fault: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_INPUT = {:#04x}",
- shortName, statusWord, statusMFR, statusInput)
- .c_str());
+ lg2::error(
+ "{SHORT_NAME} INPUT fault: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_INPUT = {STATUS_INPUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord, "STATUS_MFR_SPECIFIC",
+ lg2::hex | lg2::field8, statusMFR, "STATUS_INPUT",
+ lg2::hex | lg2::field8, statusInput);
}
inputFault++;
}
@@ -287,12 +283,13 @@
if (inputFault &&
!(statusWord & phosphor::pmbus::status_word::INPUT_FAULT_WARN))
{
- log<level::INFO>(
- std::format("{} INPUT fault cleared: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_INPUT = {:#04x}",
- shortName, statusWord, statusMFR, statusInput)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} INPUT fault cleared: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_INPUT = {STATUS_INPUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD", lg2::hex | lg2::field16,
+ statusWord, "STATUS_MFR_SPECIFIC", lg2::hex | lg2::field8,
+ statusMFR, "STATUS_INPUT", lg2::hex | lg2::field8, statusInput);
inputFault = 0;
}
}
@@ -305,13 +302,14 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format(
- "{} VOUT_OV_FAULT fault: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_VOUT = {:#02x}",
- shortName, statusWord, statusMFR, statusVout)
- .c_str());
+ lg2::error(
+ "{SHORT_NAME} VOUT_OV_FAULT fault: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_VOUT = {STATUS_VOUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord, "STATUS_MFR_SPECIFIC",
+ lg2::hex | lg2::field8, statusMFR, "STATUS_VOUT",
+ lg2::hex | lg2::field8, statusVout);
}
voutOVFault++;
@@ -331,12 +329,14 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format("{} IOUT fault: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_IOUT = {:#04x}",
- shortName, statusWord, statusMFR, statusIout)
- .c_str());
+ lg2::error(
+ "{SHORT_NAME} IOUT fault: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_IOUT = {STATUS_IOUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord, "STATUS_MFR_SPECIFIC",
+ lg2::hex | lg2::field8, statusMFR, "STATUS_IOUT",
+ lg2::hex | lg2::field8, statusIout);
}
ioutOCFault++;
@@ -357,13 +357,14 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format(
- "{} VOUT_UV_FAULT fault: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_VOUT = {:#04x}",
- shortName, statusWord, statusMFR, statusVout)
- .c_str());
+ lg2::error(
+ "{SHORT_NAME} VOUT_UV_FAULT fault: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_VOUT = {STATUS_VOUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord, "STATUS_MFR_SPECIFIC",
+ lg2::hex | lg2::field8, statusMFR, "STATUS_VOUT",
+ lg2::hex | lg2::field8, statusVout);
}
voutUVFault++;
}
@@ -382,13 +383,15 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format("{} FANS fault/warning: "
- "STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_FANS_1_2 = {:#04x}",
- shortName, statusWord, statusMFR, statusFans12)
- .c_str());
+ lg2::error("{SHORT_NAME} FANS fault/warning: "
+ "STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_FANS_1_2 = {STATUS_FANS_1_2}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord,
+ "STATUS_MFR_SPECIFIC", lg2::hex | lg2::field8,
+ statusMFR, "STATUS_FANS_1_2", lg2::hex | lg2::field8,
+ statusFans12);
}
fanFault++;
}
@@ -407,13 +410,15 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(std::format("{} TEMPERATURE fault/warning: "
- "STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_TEMPERATURE = {:#04x}",
- shortName, statusWord, statusMFR,
- statusTemperature)
- .c_str());
+ lg2::error("{SHORT_NAME} TEMPERATURE fault/warning: "
+ "STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_TEMPERATURE = {STATUS_TEMPERATURE}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord,
+ "STATUS_MFR_SPECIFIC", lg2::hex | lg2::field8,
+ statusMFR, "STATUS_TEMPERATURE",
+ lg2::hex | lg2::field8, statusTemperature);
}
tempFault++;
}
@@ -433,11 +438,13 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(std::format("{} PGOOD fault: "
- "STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}",
- shortName, statusWord, statusMFR)
- .c_str());
+ lg2::error("{SHORT_NAME} PGOOD fault: "
+ "STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord,
+ "STATUS_MFR_SPECIFIC", lg2::hex | lg2::field8,
+ statusMFR);
}
pgoodFault++;
}
@@ -499,11 +506,13 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(std::format("{} MFR fault: "
- "STATUS_WORD = {:#06x} "
- "STATUS_MFR_SPECIFIC = {:#04x}",
- shortName, statusWord, statusMFR)
- .c_str());
+ lg2::error("{SHORT_NAME} MFR fault: "
+ "STATUS_WORD = {STATUS_WORD} "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord,
+ "STATUS_MFR_SPECIFIC", lg2::hex | lg2::field8,
+ statusMFR);
}
mfrFault++;
}
@@ -524,12 +533,14 @@
{
if (statusWord != statusWordOld)
{
- log<level::ERR>(
- std::format("{} VIN_UV fault: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_INPUT = {:#04x}",
- shortName, statusWord, statusMFR, statusInput)
- .c_str());
+ lg2::error(
+ "{SHORT_NAME} VIN_UV fault: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_INPUT = {STATUS_INPUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord, "STATUS_MFR_SPECIFIC",
+ lg2::hex | lg2::field8, statusMFR, "STATUS_INPUT",
+ lg2::hex | lg2::field8, statusInput);
}
vinUVFault++;
}
@@ -540,12 +551,13 @@
{
if (vinUVFault != 0)
{
- log<level::INFO>(
- std::format("{} VIN_UV fault cleared: STATUS_WORD = {:#06x}, "
- "STATUS_MFR_SPECIFIC = {:#04x}, "
- "STATUS_INPUT = {:#04x}",
- shortName, statusWord, statusMFR, statusInput)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} VIN_UV fault cleared: STATUS_WORD = {STATUS_WORD}, "
+ "STATUS_MFR_SPECIFIC = {STATUS_MFR_SPECIFIC}, "
+ "STATUS_INPUT = {STATUS_INPUT}",
+ "SHORT_NAME", shortName, "STATUS_WORD", lg2::hex | lg2::field16,
+ statusWord, "STATUS_MFR_SPECIFIC", lg2::hex | lg2::field8,
+ statusMFR, "STATUS_INPUT", lg2::hex | lg2::field8, statusInput);
vinUVFault = 0;
}
// No AC fail, decrement counter
@@ -615,34 +627,32 @@
{
if (statusWord != statusWordOld)
{
- log<level::INFO>(std::format("{} STATUS_WORD = {:#06x}",
- shortName, statusWord)
- .c_str());
+ lg2::info("{SHORT_NAME} STATUS_WORD = {STATUS_WORD}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord);
}
// if INPUT/VIN_UV fault was on, it cleared, trace it.
if (inputFault)
{
- log<level::INFO>(
- std::format(
- "{} INPUT fault cleared: STATUS_WORD = {:#06x}",
- shortName, statusWord)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} INPUT fault cleared: STATUS_WORD = {STATUS_WORD}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord);
}
if (vinUVFault)
{
- log<level::INFO>(
- std::format("{} VIN_UV cleared: STATUS_WORD = {:#06x}",
- shortName, statusWord)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} VIN_UV cleared: STATUS_WORD = {STATUS_WORD}",
+ "SHORT_NAME", shortName, "STATUS_WORD",
+ lg2::hex | lg2::field16, statusWord);
}
if (pgoodFault > 0)
{
- log<level::INFO>(
- std::format("{} pgoodFault cleared", shortName)
- .c_str());
+ lg2::info("{SHORT_NAME} pgoodFault cleared", "SHORT_NAME",
+ shortName);
}
clearFaultFlags();
@@ -663,21 +673,20 @@
if ((inputVoltageOld == in_input::VIN_VOLTAGE_0) &&
(inputVoltage != in_input::VIN_VOLTAGE_0))
{
- log<level::INFO>(
- std::format(
- "{} READ_VIN back in range: actualInputVoltageOld = {} "
- "actualInputVoltage = {}",
- shortName, actualInputVoltageOld, actualInputVoltage)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} READ_VIN back in range: actualInputVoltageOld = {ACTUAL_INPUT_VOLTAGE_OLD} "
+ "actualInputVoltage = {ACTUAL_INPUT_VOLTAGE}",
+ "SHORT_NAME", shortName, "ACTUAL_INPUT_VOLTAGE_OLD",
+ actualInputVoltageOld, "ACTUAL_INPUT_VOLTAGE",
+ actualInputVoltage);
clearVinUVFault();
}
else if (vinUVFault && (inputVoltage != in_input::VIN_VOLTAGE_0))
{
- log<level::INFO>(
- std::format(
- "{} CLEAR_FAULTS: vinUVFault {} actualInputVoltage {}",
- shortName, vinUVFault, actualInputVoltage)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} CLEAR_FAULTS: vinUVFault {VIN_UV_FAULT} actualInputVoltage {ACTUAL_INPUT_VOLTAGE}",
+ "SHORT_NAME", shortName, "VIN_UV_FAULT", vinUVFault,
+ "ACTUAL_INPUT_VOLTAGE", actualInputVoltage);
// Do we have a VIN_UV fault latched that can now be cleared
// due to voltage back in range? Attempt to clear the
// fault(s), re-check faults on next call.
@@ -686,11 +695,11 @@
else if (std::abs(actualInputVoltageOld - actualInputVoltage) >
10.0)
{
- log<level::INFO>(
- std::format(
- "{} actualInputVoltageOld = {} actualInputVoltage = {}",
- shortName, actualInputVoltageOld, actualInputVoltage)
- .c_str());
+ lg2::info(
+ "{SHORT_NAME} actualInputVoltageOld = {ACTUAL_INPUT_VOLTAGE_OLD} actualInputVoltage = {ACTUAL_INPUT_VOLTAGE}",
+ "SHORT_NAME", shortName, "ACTUAL_INPUT_VOLTAGE_OLD",
+ actualInputVoltageOld, "ACTUAL_INPUT_VOLTAGE",
+ actualInputVoltage);
}
monitorSensors();
@@ -717,7 +726,8 @@
if (present && driverName != ACBEL_FSG032_DD_NAME)
{
- log<level::INFO>("ON_OFF_CONFIG write", entry("DATA=0x%02X", data));
+ lg2::info("ON_OFF_CONFIG write: DATA={DATA}", "DATA",
+ lg2::hex | lg2::field8, data);
try
{
std::vector<uint8_t> configData{data};
@@ -758,8 +768,8 @@
void PowerSupply::clearFaults()
{
- log<level::DEBUG>(
- std::format("clearFaults() inventoryPath: {}", inventoryPath).c_str());
+ lg2::debug("clearFaults() inventoryPath: {INVENTORY_PATH}",
+ "INVENTORY_PATH", inventoryPath);
faultLogged = false;
// The PMBus device driver does not allow for writing CLEAR_FAULTS
// directly. However, the pmbus hwmon device driver code will send a
@@ -842,9 +852,8 @@
{
present = std::get<bool>(property->second);
- log<level::INFO>(std::format("Power Supply {} Present {}",
- inventoryPath, present)
- .c_str());
+ lg2::info("Power Supply {INVENTORY_PATH} Present {PRESENT}",
+ "INVENTORY_PATH", inventoryPath, "PRESENT", present);
updateInventory();
checkAvailability();
@@ -877,9 +886,9 @@
if (vpdValue.size() != vpdSize)
{
- log<level::INFO>(std::format("{} {} resize needed. size: {}", shortName,
- vpdName, vpdValue.size())
- .c_str());
+ lg2::info("{SHORT_NAME} {VPD_NAME} resize needed. size: {SIZE}",
+ "SHORT_NAME", shortName, "VPD_NAME", vpdName, "SIZE",
+ vpdValue.size());
vpdValue.resize(vpdSize, ' ');
}
@@ -926,9 +935,8 @@
using ObjectMap = std::map<sdbusplus::message::object_path, InterfaceMap>;
ObjectMap object;
#endif
- log<level::DEBUG>(
- std::format("updateInventory() inventoryPath: {}", inventoryPath)
- .c_str());
+ lg2::debug("updateInventory() inventoryPath: {INVENTORY_PATH}",
+ "INVENTORY_PATH", inventoryPath);
if (present)
{
@@ -1017,7 +1025,7 @@
if (service.empty())
{
- log<level::ERR>("Unable to get inventory manager service");
+ lg2::error("Unable to get inventory manager service");
return;
}
@@ -1031,9 +1039,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::string(e.what() + std::string(" PATH=") + inventoryPath)
- .c_str());
+ lg2::error(
+ "Exception in updateInventory(): {ERROR}, PATH={INVENTORY_PATH}",
+ "ERROR", e, "INVENTORY_PATH", inventoryPath);
}
#endif
}
@@ -1052,16 +1060,15 @@
// Read max_power_out, should be direct format
auto maxPowerOutStr =
pmbusIntf->readString(MFR_POUT_MAX, Type::HwmonDeviceDebug);
- log<level::INFO>(std::format("{} MFR_POUT_MAX read {}", shortName,
- maxPowerOutStr)
- .c_str());
+ lg2::info("{SHORT_NAME} MFR_POUT_MAX read {MAX_POWER_OUT_STR}",
+ "SHORT_NAME", shortName, "MAX_POWER_OUT_STR",
+ maxPowerOutStr);
maxPowerOut = std::stod(maxPowerOutStr);
}
catch (const std::exception& e)
{
- log<level::ERR>(std::format("{} MFR_POUT_MAX read error: {}",
- shortName, e.what())
- .c_str());
+ lg2::error("{SHORT_NAME} MFR_POUT_MAX read error: {ERROR}",
+ "SHORT_NAME", shortName, "ERROR", e);
}
}
@@ -1149,10 +1156,9 @@
if (data.size() != recordSize)
{
- log<level::DEBUG>(
- std::format("Input history command returned {} bytes instead of 5",
- data.size())
- .c_str());
+ lg2::debug(
+ "Input history command returned {DATA_SIZE} bytes instead of 5",
+ "DATA_SIZE", data.size());
peakInputPowerSensor->value(std::numeric_limits<double>::quiet_NaN());
peakInputPowerSensor->functional(false);
return;
@@ -1204,9 +1210,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("{} READ_VIN read error: {}", shortName, e.what())
- .c_str());
+ lg2::error("{SHORT_NAME} READ_VIN read error: {ERROR}",
+ "SHORT_NAME", shortName, "ERROR", e);
}
}
}
@@ -1283,8 +1288,7 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Failed getProperty error: {}", e.what()).c_str());
+ lg2::error("Failed getProperty error: {ERROR}", "ERROR", e);
}
}