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/main.cpp b/phosphor-power-supply/main.cpp
index c48c73a..6d7c853 100644
--- a/phosphor-power-supply/main.cpp
+++ b/phosphor-power-supply/main.cpp
@@ -16,7 +16,7 @@
 #include "psu_manager.hpp"
 
 #include <CLI/CLI.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
 
@@ -45,12 +45,12 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception in main: {ERROR}", "ERROR", e);
         return -2;
     }
     catch (...)
     {
-        log<level::ERR>("Caught unexpected exception type");
+        lg2::error("Caught unexpected exception type");
         return -3;
     }
 }
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);
     }
 }
 
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index 3195a58..51cb5cb 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -124,11 +124,9 @@
     }
     catch (const std::exception& e)
     {
-        log<level::INFO>(
-            std::format(
-                "Failed to get power state, assuming it is off, error {}",
-                e.what())
-                .c_str());
+        lg2::info(
+            "Failed to get power state, assuming it is off, error {ERROR}",
+            "ERROR", e);
         powerOn = false;
         powerFaultOccurring = false;
         runValidateConfig = true;
@@ -139,10 +137,9 @@
     updateMissingPSUs();
     setPowerConfigGPIO();
 
-    log<level::INFO>(
-        std::format("initialize: power on: {}, power fault occurring: {}",
-                    powerOn, powerFaultOccurring)
-            .c_str());
+    lg2::info(
+        "initialize: power on: {POWER_ON}, power fault occurring: {POWER_FAULT_OCCURRING}",
+        "POWER_ON", powerOn, "POWER_FAULT_OCCURRING", powerFaultOccurring);
 }
 
 void PSUManager::getPSUConfiguration()
@@ -177,7 +174,7 @@
     {
         // Interface or properties not found. Let the Interfaces Added callback
         // process the information once the interfaces are added to D-Bus.
-        log<level::INFO>(std::format("No power supplies to monitor").c_str());
+        lg2::info("No power supplies to monitor");
     }
 }
 
@@ -225,7 +222,7 @@
         invpath.push_back(psuname->back());
         std::string presline = "";
 
-        log<level::DEBUG>(std::format("Inventory Path: {}", invpath).c_str());
+        lg2::debug("Inventory Path: {INVPATH}", "INVPATH", invpath);
 
         if (nullptr != preslineptr)
         {
@@ -248,10 +245,9 @@
         }
 
         buildDriverName(*i2cbus, *i2caddr);
-        log<level::DEBUG>(
-            std::format("make PowerSupply bus: {} addr: {} presline: {}",
-                        *i2cbus, *i2caddr, presline)
-                .c_str());
+        lg2::debug(
+            "make PowerSupply bus: {I2CBUS} addr: {I2CADDR} presline: {PRESLINE}",
+            "I2CBUS", *i2cbus, "I2CADDR", *i2caddr, "PRESLINE", presline);
         auto psu = std::make_unique<PowerSupply>(
             bus, invpath, *i2cbus, *i2caddr, driverName, presline,
             std::bind(
@@ -270,7 +266,7 @@
 
     if (psus.empty())
     {
-        log<level::INFO>(std::format("No power supplies to monitor").c_str());
+        lg2::info("No power supplies to monitor");
     }
     else
     {
@@ -393,9 +389,8 @@
         itIntf = interfaces.find(IBMCFFPSInterface);
         if (itIntf != interfaces.cend())
         {
-            log<level::INFO>(
-                std::format("InterfacesAdded for: {}", IBMCFFPSInterface)
-                    .c_str());
+            lg2::info("InterfacesAdded for: {IBMCFFPSINTERFACE}",
+                      "IBMCFFPSINTERFACE", IBMCFFPSInterface);
             getPSUProperties(itIntf->second);
             updateMissingPSUs();
         }
@@ -460,11 +455,9 @@
             }
         }
     }
-    log<level::INFO>(
-        std::format(
-            "powerStateChanged: power on: {}, power fault occurring: {}",
-            powerOn, powerFaultOccurring)
-            .c_str());
+    lg2::info(
+        "powerStateChanged: power on: {POWER_ON}, power fault occurring: {POWER_FAULT_OCCURRING}",
+        "POWER_ON", powerOn, "POWER_FAULT_OCCURRING", powerFaultOccurring);
 }
 
 void PSUManager::presenceChanged(sdbusplus::message_t& msg)
@@ -501,10 +494,8 @@
     }
     catch (const std::exception& e)
     {
-        log<level::INFO>(
-            std::format("Failed calling setPowerSupplyError due to error {}",
-                        e.what())
-                .c_str());
+        lg2::info("Failed calling setPowerSupplyError due to error {ERROR}",
+                  "ERROR", e);
     }
 }
 
@@ -525,7 +516,7 @@
 
         if (service.empty())
         {
-            log<level::ERR>("Unable to get logging manager service");
+            lg2::error("Unable to get logging manager service");
             return;
         }
 
@@ -540,11 +531,9 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(
-            std::format(
-                "Failed creating event log for fault {} due to error {}",
-                faultName, e.what())
-                .c_str());
+        lg2::error(
+            "Failed creating event log for fault {FAULT_NAME} due to error {ERROR}",
+            "FAULT_NAME", faultName, "ERROR", e);
     }
 }
 
@@ -561,16 +550,16 @@
             catch (const std::exception& e)
             {
                 // Not an error, system just hasn't implemented the synch gpio
-                log<level::INFO>("No synchronization GPIO found");
+                lg2::info("No synchronization GPIO found");
                 syncHistoryGPIO = nullptr;
             }
         }
         if (syncHistoryGPIO)
         {
             const std::chrono::milliseconds delay{INPUT_HISTORY_SYNC_DELAY};
-            log<level::INFO>("Synchronize INPUT_HISTORY");
+            lg2::info("Synchronize INPUT_HISTORY");
             syncHistoryGPIO->toggleLowHigh(delay);
-            log<level::INFO>("Synchronize INPUT_HISTORY completed");
+            lg2::info("Synchronize INPUT_HISTORY completed");
         }
     }
 
@@ -842,11 +831,10 @@
                                std::to_string(acFailedCount));
         additionalData.emplace("PGOOD_FAULT_COUNT",
                                std::to_string(pgoodFailedCount));
-        log<level::INFO>(
-            std::format(
-                "Brownout detected, not present count: {}, AC fault count {}, pgood fault count: {}",
-                notPresentCount, acFailedCount, pgoodFailedCount)
-                .c_str());
+        lg2::info(
+            "Brownout detected, not present count: {NOT_PRESENT_COUNT}, AC fault count {AC_FAILED_COUNT}, pgood fault count: {PGOOD_FAILED_COUNT}",
+            "NOT_PRESENT_COUNT", notPresentCount, "AC_FAILED_COUNT",
+            acFailedCount, "PGOOD_FAILED_COUNT", pgoodFailedCount);
 
         createError("xyz.openbmc_project.State.Shutdown.Power.Error.Blackout",
                     additionalData);
@@ -877,11 +865,10 @@
                     // Indicate that the system is no longer in a brownout
                     // condition by setting the PowerSystemInputs status
                     // property to Good.
-                    log<level::INFO>(
-                        std::format(
-                            "Brownout cleared, not present count: {}, AC fault count {}, pgood fault count: {}",
-                            notPresentCount, acFailedCount, pgoodFailedCount)
-                            .c_str());
+                    lg2::info(
+                        "Brownout cleared, not present count: {NOT_PRESENT_COUNT}, AC fault count {AC_FAILED_COUNT}, pgood fault count: {PGOOD_FAILED_COUNT}",
+                        "NOT_PRESENT_COUNT", notPresentCount, "AC_FAILED_COUNT",
+                        acFailedCount, "PGOOD_FAILED_COUNT", pgoodFailedCount);
                     powerSystemInputs.status(
                         sdbusplus::xyz::openbmc_project::State::Decorator::
                             server::PowerSystemInputs::Status::Good);
@@ -890,10 +877,8 @@
             }
             catch (const std::exception& e)
             {
-                log<level::ERR>(
-                    std::format("Error trying to clear brownout, error: {}",
-                                e.what())
-                        .c_str());
+                lg2::error("Error trying to clear brownout, error: {ERROR}",
+                           "ERROR", e);
             }
         }
     }
@@ -940,10 +925,9 @@
                 propReadFail = true;
                 // 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",
-                                psuInventoryPath)
-                        .c_str());
+                lg2::info(
+                    "D-Bus property {PSU_INVENTORY_PATH} access failure exception",
+                    "PSU_INVENTORY_PATH", psuInventoryPath);
             }
 
             if (psuModel.empty())
@@ -1325,9 +1309,9 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(std::format("Failed to find device driver {}, error {}",
-                                    symLinkPath, e.what())
-                            .c_str());
+        lg2::error(
+            "Failed to find device driver {SYM_LINK_PATH}, error {ERROR}",
+            "SYM_LINK_PATH", symLinkPath, "ERROR", e);
     }
 }
 
diff --git a/phosphor-power-supply/psu_manager.hpp b/phosphor-power-supply/psu_manager.hpp
index 79caa96..01c56c2 100644
--- a/phosphor-power-supply/psu_manager.hpp
+++ b/phosphor-power-supply/psu_manager.hpp
@@ -4,7 +4,7 @@
 #include "types.hpp"
 #include "utility.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus/match.hpp>
 #include <sdbusplus/server/manager.hpp>
 #include <sdbusplus/server/object.hpp>
diff --git a/phosphor-power-supply/util.cpp b/phosphor-power-supply/util.cpp
index 54f6eb7..73c7ff5 100644
--- a/phosphor-power-supply/util.cpp
+++ b/phosphor-power-supply/util.cpp
@@ -47,7 +47,7 @@
 
     if (!line)
     {
-        log<level::ERR>("Failed line");
+        lg2::error("Failed line in GPIOInterface::read()");
         throw std::runtime_error{std::string{"Failed to find line"}};
     }
 
@@ -61,9 +61,7 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>(
-                std::format("Failed to get_value of GPIO line: {}", e.what())
-                    .c_str());
+            lg2::error("Failed to get_value of GPIO line: {ERROR}", "ERROR", e);
             line.release();
             throw;
         }
@@ -72,8 +70,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Failed to request GPIO line",
-                        entry("MSG=%s", e.what()));
+        lg2::error("Failed to request GPIO line: {MSG}", "MSG", e);
         throw;
     }
 
@@ -86,7 +83,7 @@
 
     if (!line)
     {
-        log<level::ERR>("Failed line");
+        lg2::error("Failed line in GPIOInterface::write");
         throw std::runtime_error{std::string{"Failed to find line"}};
     }
 
@@ -100,8 +97,8 @@
     }
     catch (std::exception& e)
     {
-        log<level::ERR>("Failed to set GPIO line", entry("MSG=%s", e.what()),
-                        entry("VALUE=%d", value));
+        lg2::error("Failed to set GPIO line, MSG={MSG}, VALUE={VALUE}", "MSG",
+                   e, "VALUE", value);
         throw;
     }
 }
diff --git a/phosphor-power-supply/util.hpp b/phosphor-power-supply/util.hpp
index f432af0..58bab67 100644
--- a/phosphor-power-supply/util.hpp
+++ b/phosphor-power-supply/util.hpp
@@ -6,7 +6,7 @@
 #include <gpiod.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <bitset>
 #include <chrono>
@@ -42,10 +42,9 @@
                      bool present, const std::string& name) const override
     {
         using namespace phosphor::logging;
-        log<level::INFO>(std::format("Updating inventory present property. "
-                                     "present:{} invpath:{} name:{}",
-                                     present, invpath, name)
-                             .c_str());
+        lg2::info("Updating inventory present property. "
+                  "present:{PRESENT} invpath:{INVPATH} name:{NAME}",
+                  "PRESENT", present, "INVPATH", invpath, "NAME", name);
 
         using InternalFailure =
             sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -79,11 +78,9 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>(
-                std::format(
-                    "Error in inventory manager call to update inventory: {}",
-                    e.what())
-                    .c_str());
+            lg2::error(
+                "Error in inventory manager call to update inventory: {ERROR}",
+                "ERROR", e);
             elog<InternalFailure>();
         }
     }
@@ -114,11 +111,9 @@
         catch (const sdbusplus::exception_t& e)
         {
             using namespace phosphor::logging;
-            log<level::ERR>(
-                std::format("Error in inventory manager call to update "
-                            "availability interface: {}",
-                            e.what())
-                    .c_str());
+            lg2::error("Error in inventory manager call to update "
+                       "availability interface: {ERROR}",
+                       "ERROR", e);
             throw;
         }
     }
@@ -187,10 +182,9 @@
         catch (const sdbusplus::exception_t& e)
         {
             using namespace phosphor::logging;
-            log<level::INFO>(std::format("Error trying to handle health rollup "
-                                         "associations for {}: {}",
-                                         invpath, e.what())
-                                 .c_str());
+            lg2::info("Error trying to handle health rollup "
+                      "associations for {INVPATH}: {ERROR}",
+                      "INVPATH", invpath, "ERROR", e);
         }
     }