Updated Miscellaneous Journal Traces to lg2

Update the logging API used for files not in
phosphor-fan-presence/presence, phosphor-fan-presence/monitor,
or phosphor-fan-presence/control from the older phosphor::logging::log
to the more recent lg2::log.

Tested:
* Verified journal traces worked correctly in simulation and on
  physical hardware.
* Modified json config files to force parsing and sensor-monitor
  errors and verified correct output and key/value pairs in the
  journalctl output.

Change-Id: Ie68ac5733ecd20d5f17882020df861a975121f77
Signed-off-by: Anwaar Hadi <anwaar.hadi@ibm.com>
diff --git a/cooling-type/cooling_type.cpp b/cooling-type/cooling_type.cpp
index 774d389..73d4b40 100644
--- a/cooling-type/cooling_type.cpp
+++ b/cooling-type/cooling_type.cpp
@@ -9,12 +9,10 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
-#include <format>
-
 namespace phosphor
 {
 namespace cooling
@@ -37,11 +35,9 @@
         return decltype(evdevOpen(0))(gpioDev);
     }
 
-    log<level::ERR>(
-        std::format(
-            "Failed to get libevdev from file descriptor {}, return code {}",
-            fd, rc)
-            .c_str());
+    lg2::error(
+        "Failed to get libevdev from file descriptor {FD}, return code {RC}",
+        "FD", fd, "RC", rc);
     elog<InternalFailure>();
     return decltype(evdevOpen(0))(nullptr);
 }
@@ -69,10 +65,8 @@
         libevdev_fetch_event_value(gpioDev.get(), EV_KEY, keycode, &value);
     if (0 == fetch_rc)
     {
-        log<level::ERR>(
-            std::format("Device does not support event type keycode {}",
-                        keycode)
-                .c_str());
+        lg2::error("Device does not support event type keycode {KEYCODE}",
+                   "KEYCODE", keycode);
         elog<InternalFailure>();
     }
 
diff --git a/cooling-type/main.cpp b/cooling-type/main.cpp
index 3409210..85f5294 100644
--- a/cooling-type/main.cpp
+++ b/cooling-type/main.cpp
@@ -2,10 +2,9 @@
 #include "sdbusplus.hpp"
 
 #include <CLI/CLI.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 
-#include <format>
 #include <iostream>
 #include <memory>
 
@@ -47,7 +46,7 @@
 
     if (objpath.empty())
     {
-        log<level::ERR>("Bus path argument required");
+        lg2::error("Bus path argument required");
         return rc;
     }
 
@@ -70,7 +69,7 @@
         {
             if (keycode.empty())
             {
-                log<level::ERR>("--event=<keycode> argument required\n");
+                lg2::error("--event=<keycode> argument required\n");
                 return rc;
             }
             auto gpiocode = std::stoul(keycode);
@@ -82,18 +81,17 @@
     }
     catch (const DBusMethodError& dme)
     {
-        log<level::ERR>(
-            std::format("Uncaught DBus method failure exception "
-                        "Busname: {} "
-                        "Path: {} "
-                        "Interface: {} "
-                        "Method: {}",
-                        dme.busName, dme.path, dme.interface, dme.method)
-                .c_str());
+        lg2::error("Uncaught DBus method failure exception "
+                   "Busname: {BUSNAME} "
+                   "Path: {PATH} "
+                   "Interface: {INTERFACE} "
+                   "Method: {METHOD}",
+                   "BUSNAME", dme.busName, "PATH", dme.path, "INTERFACE",
+                   dme.interface, "METHOD", dme.method);
     }
     catch (const std::exception& err)
     {
-        log<phosphor::logging::level::ERR>(err.what());
+        lg2::error("Error with Cooling Type: {ERROR}", "ERROR", err);
     }
 
     return rc;
diff --git a/evdevpp/evdev.hpp b/evdevpp/evdev.hpp
index 543729c..e68ad7c 100644
--- a/evdevpp/evdev.hpp
+++ b/evdevpp/evdev.hpp
@@ -6,6 +6,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 #include <memory>
@@ -74,8 +75,9 @@
         auto rc = libevdev_fetch_event_value(evdev.get(), type, code, &val);
         if (!rc)
         {
-            log<level::ERR>("Error in call to libevdev_fetch_event_value",
-                            entry("TYPE=%d", type), entry("CODE=%d", code));
+            lg2::error(
+                "Error in call to libevdev_fetch_event_value, Type={TYPE}, Code={CODE}",
+                "TYPE", type, "CODE", code);
             elog<InternalFailure>();
         }
 
@@ -92,8 +94,8 @@
                                           LIBEVDEV_READ_FLAG_NORMAL, &ev);
             if (rc < 0)
             {
-                log<level::ERR>("Error in call to libevdev_next_event",
-                                entry("RC=%d", rc));
+                lg2::error("Error in call to libevdev_next_event, RC={RC}",
+                           "RC", rc);
                 elog<InternalFailure>();
             }
 
@@ -124,8 +126,8 @@
 
     if (rc)
     {
-        log<level::ERR>("Error in call to libevdev_new_from_fd",
-                        entry("RC=%d", rc), entry("FD=%d", fd));
+        lg2::error("Error in call to libevdev_new_from_fd, RC={RC}, FD={FD}",
+                   "RC", rc, "FD", fd);
         elog<InternalFailure>();
     }
 
diff --git a/json_config.hpp b/json_config.hpp
index 52dd505..87c6d1b 100644
--- a/json_config.hpp
+++ b/json_config.hpp
@@ -18,7 +18,7 @@
 #include "sdbusplus.hpp"
 
 #include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/source/signal.hpp>
 
@@ -299,9 +299,8 @@
 
         if (!confFile.empty() && fs::exists(confFile))
         {
-            log<level::INFO>(
-                std::format("Loading configuration from {}", confFile.string())
-                    .c_str());
+            lg2::info("Loading configuration from {CONFFILE}", "CONFFILE",
+                      confFile);
             file.open(confFile);
             try
             {
@@ -310,11 +309,9 @@
             }
             catch (const std::exception& e)
             {
-                log<level::ERR>(
-                    std::format(
-                        "Failed to parse JSON config file: {}, error: {}",
-                        confFile.string(), e.what())
-                        .c_str());
+                lg2::error(
+                    "Failed to parse JSON config file: {CONFFILE}, error: {ERROR}",
+                    "CONFFILE", confFile, "ERROR", e);
                 throw std::runtime_error(
                     std::format(
                         "Failed to parse JSON config file: {}, error: {}",
@@ -324,9 +321,8 @@
         }
         else
         {
-            log<level::ERR>(std::format("Unable to open JSON config file: {}",
-                                        confFile.string())
-                                .c_str());
+            lg2::error("Unable to open JSON config file: {CONFFILE}",
+                       "CONFFILE", confFile);
             throw std::runtime_error(
                 std::format("Unable to open JSON config file: {}",
                             confFile.string())
diff --git a/logger.hpp b/logger.hpp
index 77ad13a..bd40f55 100644
--- a/logger.hpp
+++ b/logger.hpp
@@ -5,7 +5,7 @@
 #include <unistd.h>
 
 #include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <cassert>
 #include <ctime>
@@ -76,13 +76,11 @@
     {
         if (priority == Logger::error)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                message.c_str());
+            lg2::error("{MSG}", "MSG", message);
         }
         else if (priority != Logger::quiet)
         {
-            phosphor::logging::log<phosphor::logging::level::INFO>(
-                message.c_str());
+            lg2::info("{MSG}", "MSG", message);
         }
 
         if (_entries.size() == _maxEntries)
diff --git a/sdbusplus.hpp b/sdbusplus.hpp
index 52c2a7e..086ef99 100644
--- a/sdbusplus.hpp
+++ b/sdbusplus.hpp
@@ -2,7 +2,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/bus/match.hpp>
 #include <sdbusplus/message.hpp>
@@ -223,11 +223,9 @@
         auto mapperResp = getSubTreeRaw(bus, path, interface, depth);
         if (mapperResp.empty())
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Empty response from mapper GetSubTree",
-                phosphor::logging::entry("SUBTREE=%s", path.c_str()),
-                phosphor::logging::entry("INTERFACE=%s", interface.c_str()),
-                phosphor::logging::entry("DEPTH=%u", depth));
+            lg2::error(
+                "Empty response from mapper GetSubTree, SubTree={SUBTREE}, Interface={INTERFACE}, Depth={DEPTH}",
+                "SUBTREE", path, "INTERFACE", interface, "DEPTH", depth);
             phosphor::logging::elog<detail::errors::InternalFailure>();
         }
         return mapperResp;
@@ -260,11 +258,9 @@
         auto mapperResp = getSubTreePathsRaw(bus, path, interface, depth);
         if (mapperResp.empty())
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Empty response from mapper GetSubTreePaths",
-                phosphor::logging::entry("SUBTREE=%s", path.c_str()),
-                phosphor::logging::entry("INTERFACE=%s", interface.c_str()),
-                phosphor::logging::entry("DEPTH=%u", depth));
+            lg2::error(
+                "Empty response from mapper GetSubTreePaths, SubTree={SUBTREE}, Interface={INTERFACE}, Depth={DEPTH}",
+                "SUBTREE", path, "INTERFACE", interface, "DEPTH", depth);
             phosphor::logging::elog<detail::errors::InternalFailure>();
         }
         return mapperResp;
@@ -296,8 +292,7 @@
             {
                 // Should never happen.  A missing object would fail
                 // in callMethodAndRead()
-                phosphor::logging::log<phosphor::logging::level::ERR>(
-                    "Empty mapper response on service lookup");
+                lg2::error("Empty mapper response on service lookup");
                 throw DBusServiceError{path, interface};
             }
             return mapperResp.begin()->first;
diff --git a/sensor-monitor/alarm_timestamps.hpp b/sensor-monitor/alarm_timestamps.hpp
index b5889a9..5886dc4 100644
--- a/sensor-monitor/alarm_timestamps.hpp
+++ b/sensor-monitor/alarm_timestamps.hpp
@@ -22,12 +22,11 @@
 #include <cereal/types/string.hpp>
 #include <cereal/types/tuple.hpp>
 #include <cereal/types/vector.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdeventplus/clock.hpp>
 #include <sdeventplus/utility/timer.hpp>
 
 #include <filesystem>
-#include <format>
 #include <fstream>
 #include <map>
 #include <tuple>
@@ -242,13 +241,10 @@
         catch (const std::exception& e)
         {
             // Include possible exception when removing file, otherwise ec = 0
-            using namespace phosphor::logging;
             std::error_code ec;
             std::filesystem::remove(path, ec);
-            log<level::ERR>(
-                std::format("Unable to restore persisted times ({}, ec: {})",
-                            e.what(), ec.value())
-                    .c_str());
+            lg2::error("Unable to restore persisted times ({ERROR}, ec: {EC})",
+                       "ERROR", e, "EC", ec.value());
         }
     }
 
diff --git a/sensor-monitor/shutdown_alarm_monitor.cpp b/sensor-monitor/shutdown_alarm_monitor.cpp
index 1cdb547..03df62d 100644
--- a/sensor-monitor/shutdown_alarm_monitor.cpp
+++ b/sensor-monitor/shutdown_alarm_monitor.cpp
@@ -19,14 +19,11 @@
 
 #include <unistd.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
 
-#include <format>
-
 namespace sensor::monitor
 {
-using namespace phosphor::logging;
 using namespace phosphor::fan::util;
 using namespace phosphor::fan;
 namespace fs = std::filesystem;
@@ -160,9 +157,8 @@
         catch (const DBusServiceError& e)
         {
             // The sensor isn't on D-Bus anymore
-            log<level::INFO>(std::format("No {} interface on {} anymore.",
-                                         interface, sensorPath)
-                                 .c_str());
+            lg2::info("No {INTERFACE} interface on {SENSOR_PATH} anymore.",
+                      "INTERFACE", interface, "SENSOR_PATH", sensorPath);
             continue;
         }
 
@@ -281,11 +277,10 @@
     {
         const uint64_t& original = previousStartTime->second;
 
-        log<level::INFO>(std::format("Found previously running {} timer "
-                                     "for {} with start time {}",
-                                     propertyName, sensorPath, original)
-                             .c_str());
-
+        lg2::info("Found previously running {PROPERTY_NAME} timer "
+                  "for {SENSOR_PATH} with start time {START_TIME}",
+                  "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath,
+                  "START_TIME", original);
         // Sanity check it isn't total garbage.
         if (now > original)
         {
@@ -302,19 +297,18 @@
         }
         else
         {
-            log<level::WARNING>(
-                std::format(
-                    "Restarting {} shutdown timer for {} for full "
-                    "time because saved time {} is after current time {}",
-                    propertyName, sensorPath, original, now)
-                    .c_str());
+            lg2::warning(
+                "Restarting {PROPERTY_NAME} shutdown timer for {SENSOR_PATH} for full "
+                "time because saved time {SAVED_TIME} is after current time {CURRENT_TIME}",
+                "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath,
+                "SAVED_TIME", original, "CURRENT_TIME", now);
         }
     }
 
-    log<level::INFO>(
-        std::format("Starting {}ms {} shutdown timer due to sensor {} value {}",
-                    shutdownDelay.count(), propertyName, sensorPath, *value)
-            .c_str());
+    lg2::info(
+        "Starting {TIME}ms {PROPERTY_NAME} shutdown timer due to sensor {SENSOR_PATH} value {VALUE}",
+        "TIME", shutdownDelay.count(), "PROPERTY_NAME", propertyName,
+        "SENSOR_PATH", sensorPath, "VALUE", *value);
 
     auto& timer = alarm->second;
 
@@ -345,11 +339,10 @@
 
     createEventLog(alarmKey, false, value);
 
-    log<level::INFO>(
-        std::format("Stopping {} shutdown timer due to sensor {} value {}",
-                    propertyName, sensorPath, value)
-            .c_str());
-
+    lg2::info(
+        "Stopping {PROPERTY_NAME} shutdown timer due to sensor {SENSOR_PATH} value {VALUE}",
+        "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath, "VALUE",
+        value);
     auto& timer = alarm->second;
     timer->setEnabled(false);
     timer.reset();
@@ -369,10 +362,8 @@
     }
     catch (const std::exception& e)
     {
-        auto message = std::format(
-            "Caught exception while creating BMC dump: {}", e.what());
-
-        log<level::ERR>(message.c_str());
+        lg2::error("Caught exception while creating BMC dump: {ERROR}", "ERROR",
+                   e);
     }
 }
 
@@ -384,11 +375,9 @@
     auto value = SDBusPlus::getProperty<double>(bus, sensorPath, valueInterface,
                                                 valueProperty);
 
-    log<level::ERR>(
-        std::format(
-            "The {} shutdown timer expired for sensor {}, shutting down",
-            propertyName, sensorPath)
-            .c_str());
+    lg2::error(
+        "The {PROPERTY_NAME} shutdown timer expired for sensor {SENSOR_PATH}, shutting down",
+        "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath);
 
     // Re-send the event log.  If someone didn't want this it could be
     // wrapped by a compile option.
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index 545f01e..54f5a8a 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -21,16 +21,13 @@
 
 #include <unistd.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
 
-#include <format>
-
 namespace sensor::monitor
 {
 
 using namespace sdbusplus::xyz::openbmc_project::Logging::server;
-using namespace phosphor::logging;
 using namespace phosphor::fan;
 using namespace phosphor::fan::util;
 
@@ -292,10 +289,8 @@
     auto properties = it->second.find(alarmProperty);
     if (properties == it->second.end())
     {
-        log<level::INFO>(
-            std::format("Could not find {} in threshold alarms map",
-                        alarmProperty)
-                .c_str());
+        lg2::info("Could not find {ALARM_PROPERTY} in threshold alarms map",
+                  "ALARM_PROPERTY", alarmProperty);
         return;
     }
 
@@ -309,10 +304,10 @@
 
         ad.emplace("SENSOR_VALUE", std::to_string(sensorValue));
 
-        log<level::INFO>(
-            std::format("Threshold Event {} {} = {} (sensor value {})",
-                        sensorPath, alarmProperty, alarmValue, sensorValue)
-                .c_str());
+        lg2::info(
+            "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE} (sensor value {SENSOR_VALUE})",
+            "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+            "ALARM_VALUE", alarmValue, "SENSOR_VALUE", sensorValue);
     }
     catch (const DBusServiceError& e)
     {
@@ -320,9 +315,10 @@
         // not be in the mapper yet.  This could only happen if the sensor
         // application was started up after this one and the value exceeded the
         // threshold immediately.
-        log<level::INFO>(std::format("Threshold Event {} {} = {}", sensorPath,
-                                     alarmProperty, alarmValue)
-                             .c_str());
+        lg2::info(
+            "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE}",
+            "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+            "ALARM_VALUE", alarmValue);
     }
 
     auto callout = getCallout(sensorPath);
@@ -345,16 +341,17 @@
 
         ad.emplace("THRESHOLD_VALUE", std::to_string(thresholdValue));
 
-        log<level::INFO>(
-            std::format("Threshold Event {} {} = {} (threshold value {})",
-                        sensorPath, alarmProperty, alarmValue, thresholdValue)
-                .c_str());
+        lg2::info(
+            "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE} (threshold value {THRESHOLD_VALUE})",
+            "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+            "ALARM_VALUE", alarmValue, "THRESHOLD_VALUE", thresholdValue);
     }
     catch (const DBusServiceError& e)
     {
-        log<level::INFO>(std::format("Threshold Event {} {} = {}", sensorPath,
-                                     alarmProperty, alarmValue)
-                             .c_str());
+        lg2::info(
+            "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE}",
+            "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+            "ALARM_VALUE", alarmValue);
     }
 
     type.front() = toupper(type.front());
@@ -373,10 +370,8 @@
     auto pos = sensorPath.find_last_of('/');
     if ((sensorPath.back() == '/') || (pos == std::string::npos))
     {
-        log<level::ERR>(
-            std::format("Cannot get sensor name from sensor path {}",
-                        sensorPath)
-                .c_str());
+        lg2::error("Cannot get sensor name from sensor path {SENSOR_PATH}",
+                   "SENSOR_PATH", sensorPath);
         return "unknown_sensor";
     }
 
@@ -388,10 +383,8 @@
     auto pos = sensorPath.find_last_of('/');
     if ((sensorPath.back() == '/') || (pos == std::string::npos))
     {
-        log<level::ERR>(
-            std::format("Cannot get sensor type from sensor path {}",
-                        sensorPath)
-                .c_str());
+        lg2::error("Cannot get sensor type from sensor path {SENSOR_PATH}",
+                   "SENSOR_PATH", sensorPath);
         throw std::runtime_error("Invalid sensor path");
     }
 
diff --git a/utility.hpp b/utility.hpp
index 727b557..a55a52f 100644
--- a/utility.hpp
+++ b/utility.hpp
@@ -5,12 +5,10 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
-#include <format>
-
 using namespace phosphor::logging;
 using InternalFailure =
     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -66,9 +64,8 @@
         fd = ::open(pathname.c_str(), flags);
         if (-1 == fd)
         {
-            log<level::ERR>(
-                std::format("Failed to open file device path {}", pathname)
-                    .c_str());
+            lg2::error("Failed to open file device path {PATH}", "PATH",
+                       pathname);
             elog<InternalFailure>();
         }
     }