logging: switch to lg2

After switching to C++20, it is recommended to use `phosphor::lg2`
to format log, and the correct `CODE_LINE` and `CODE_FUNC` values
can be used in log tracking.

Tested: built ledManager successfully and Unit Test passes.

Before: The file does not exist or is empty
After: The file does not exist or is empty, FILE_PATH = /usr/share/phosphor-led-manager/lamp-test-led-overrides.json

MESSAGE=File does not exist, FILE_PATH = /var/lib/phosphor-led-manager/savedGroups
LOG2_FMTMSG=File does not exist, FILE_PATH = {PATH}
CODE_FILE=../../../../../../fp5280g2-workspace/sources/phosphor-led-manager/serialize.cpp
CODE_LINE=63
CODE_FUNC=void phosphor::led::Serialize::restoreGroups()
PATH=/var/lib/phosphor-led-manager/savedGroups
SYSLOG_IDENTIFIER=phosphor-ledmanager
_PID=298
_COMM=phosphor-ledman
_EXE=/usr/bin/phosphor-ledmanager
_CMDLINE=phosphor-ledmanager
_SYSTEMD_CGROUP=/system.slice/xyz.openbmc_project.LED.GroupManager.service
_SYSTEMD_UNIT=xyz.openbmc_project.LED.GroupManager.service
_SYSTEMD_INVOCATION_ID=5ddd4960a3b04fe29c34e4ce03b6be06

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I5ec8530e0b539bcf8d7d211c802430698aebd343
diff --git a/fault-monitor/fru-fault-monitor.cpp b/fault-monitor/fru-fault-monitor.cpp
index 047994f..57c7b78 100644
--- a/fault-monitor/fru-fault-monitor.cpp
+++ b/fault-monitor/fru-fault-monitor.cpp
@@ -3,6 +3,7 @@
 #include "elog-errors.hpp"
 
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/exception.hpp>
 #include <xyz/openbmc_project/Led/Fru/Monitor/error.hpp>
 #include <xyz/openbmc_project/Led/Mapper/error.hpp>
@@ -63,9 +64,9 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>(
-            "Failed to GetObject or parse getService mapper response",
-            entry("ERROR=%s", e.what()));
+        lg2::error(
+            "Failed to parse getService mapper response, ERROR = {ERROR}",
+            "ERROR", e);
         using namespace xyz::openbmc_project::Led::Mapper;
         elog<ObjectNotFoundErr>(ObjectNotFoundError::METHOD_NAME("GetObject"),
                                 ObjectNotFoundError::PATH(path.c_str()),
@@ -127,8 +128,7 @@
     catch (const sdbusplus::exception::exception& e)
     {
         // Log an info message, system may not have all the LED Groups defined
-        log<level::INFO>("Failed to Assert LED Group",
-                         entry("ERROR=%s", e.what()));
+        lg2::info("Failed to Assert LED Group, ERROR = {ERROR}", "ERROR", e);
     }
 
     return;
@@ -146,9 +146,8 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Failed to parse created message",
-                        entry("ERROR=%s", e.what()),
-                        entry("REPLY_SIG=%s", msg.get_signature()));
+        lg2::error("Failed to parse created message, ERROR = {ERROR}", "ERROR",
+                   e);
         return;
     }
 
@@ -166,8 +165,9 @@
 
     // Nothing else shows when a specific error log
     // has been created. Do it here.
-    std::string message{objectPath.str + " created"};
-    log<level::INFO>(message.c_str());
+    // TODO:(phosphor-logging#25): support sdbusplus::message::object_path
+    // directly.
+    lg2::info("{PATH} created", "PATH", objectPath.str);
 
     auto attr = iter->second.find("Associations");
     if (attr == iter->second.end())
@@ -211,8 +211,9 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Failed to parse existing callouts subtree message",
-                        entry("ERROR=%s", e.what()));
+        lg2::error(
+            "Failed to parse existing callouts subtree message, ERROR = {ERROR}",
+            "ERROR", e);
     }
 }
 
@@ -238,7 +239,7 @@
         if (reply.is_method_error())
         {
             // do not stop, continue with next elog
-            log<level::ERR>("Error in getting associations");
+            lg2::error("Error in getting associations");
             continue;
         }
 
@@ -249,9 +250,9 @@
         }
         catch (const sdbusplus::exception::exception& e)
         {
-            log<level::ERR>("Failed to get Associations or  parse existing "
-                            "callouts associations message",
-                            entry("ERROR=%s", e.what()));
+            lg2::error(
+                "Failed to parse existing callouts associations message, ERROR = {ERROR}",
+                "ERROR", e);
             continue;
         }
         auto& assocs = std::get<AssociationList>(assoc);
diff --git a/fault-monitor/operational-status-monitor.cpp b/fault-monitor/operational-status-monitor.cpp
index 66c6d3f..ffed55f 100644
--- a/fault-monitor/operational-status-monitor.cpp
+++ b/fault-monitor/operational-status-monitor.cpp
@@ -1,6 +1,7 @@
 #include "operational-status-monitor.hpp"
 
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 namespace phosphor
 {
@@ -12,7 +13,6 @@
 {
 namespace monitor
 {
-using namespace phosphor::logging;
 
 void Monitor::matchHandler(sdbusplus::message::message& msg)
 {
@@ -32,8 +32,9 @@
         const bool* value = std::get_if<bool>(&it->second);
         if (!value)
         {
-            log<level::ERR>("Faild to get the Functional property",
-                            entry("INVENTORY_PATH=%s", invObjectPath.c_str()));
+            lg2::error(
+                "Faild to get the Functional property, INVENTORY_PATH = {PATH}",
+                "PATH", invObjectPath);
             return;
         }
 
@@ -42,9 +43,10 @@
         auto ledGroupPath = getLedGroupPaths(invObjectPath);
         if (ledGroupPath.empty())
         {
-            log<level::INFO>("The inventory D-Bus object is not associated "
-                             "with the LED group D-Bus object.",
-                             entry("INVENTORY_PATH=%s", invObjectPath.c_str()));
+            lg2::info(
+                "The inventory D-Bus object is not associated with the LED "
+                "group D-Bus object. INVENTORY_PATH = {PATH}",
+                "PATH", invObjectPath);
             return;
         }
 
@@ -72,9 +74,9 @@
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("Failed to get endpoints property",
-                        entry("ERROR=%s", e.what()),
-                        entry("PATH=%s", faultLedAssociation.c_str()));
+        lg2::error(
+            "Failed to get endpoints property, ERROR = {ERROR}, PATH = {PATH}",
+            "ERROR", e, "PATH", faultLedAssociation);
 
         return {};
     }
@@ -100,9 +102,9 @@
         }
         catch (const sdbusplus::exception::exception& e)
         {
-            log<level::ERR>("Failed to set Asserted property",
-                            entry("ERROR=%s", e.what()),
-                            entry("PATH=%s", path.c_str()));
+            lg2::error(
+                "Failed to set Asserted property, ERROR = {ERROR}, PATH = {PATH}",
+                "ERROR", e, "PATH", path);
         }
     }
 }