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.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I7de1e3782363c0c7f57ff917cf9487e4599cac8e
diff --git a/mslverify/util.hpp b/mslverify/util.hpp
index 3792908..6ee1e81 100644
--- a/mslverify/util.hpp
+++ b/mslverify/util.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/message.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
@@ -44,11 +44,8 @@
 
     if (respMsg.is_method_error())
     {
-        phosphor::logging::log<phosphor::logging::level::INFO>(
-            "Failed to invoke DBus method.",
-            phosphor::logging::entry("PATH=%s", path.c_str()),
-            phosphor::logging::entry("INTERFACE=%s", interface.c_str()),
-            phosphor::logging::entry("METHOD=%s", method.c_str()));
+        lg2::error("Failed to invoke DBus method. {PATH}, {INTF}, {METHOD}",
+                   "PATH", path, "INTF", interface, "METHOD", method);
         phosphor::logging::elog<detail::errors::InternalFailure>();
     }
 
@@ -105,10 +102,8 @@
 
     if (mapperResp.empty())
     {
-        phosphor::logging::log<phosphor::logging::level::INFO>(
-            "Object not found.",
-            phosphor::logging::entry("PATH=%s", path.c_str()),
-            phosphor::logging::entry("INTERFACE=%s", interface.c_str()));
+        lg2::error("Object not found. {PATH}, {INTF}", "PATH", path, "INTF",
+                   interface);
         phosphor::logging::elog<detail::errors::InternalFailure>();
     }
     return mapperResp.begin()->first;
diff --git a/mslverify/verify.cpp b/mslverify/verify.cpp
index f86ed1f..d322b8b 100644
--- a/mslverify/verify.cpp
+++ b/mslverify/verify.cpp
@@ -92,9 +92,8 @@
 
     if (!result)
     {
-        phosphor::logging::log<phosphor::logging::level::INFO>(
-            "The physical system configuration does not "
-            "satisfy the minimum ship level.");
+        lg2::info(
+            "The physical system configuration does not satisfy the minimum ship level.");
 
         return 1;
     }
diff --git a/src/event.hpp b/src/event.hpp
index 13c6d52..a4372c6 100644
--- a/src/event.hpp
+++ b/src/event.hpp
@@ -3,8 +3,6 @@
 #include "callback.hpp"
 #include "event_manager.hpp"
 
-#include <phosphor-logging/log.hpp>
-
 #include <sstream>
 #include <string>
 
diff --git a/src/event_serialize.cpp b/src/event_serialize.cpp
index d598bf4..5340a80 100644
--- a/src/event_serialize.cpp
+++ b/src/event_serialize.cpp
@@ -5,7 +5,7 @@
 #include <cereal/archives/binary.hpp>
 #include <cereal/types/string.hpp>
 #include <cereal/types/vector.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <fstream>
 
@@ -19,8 +19,6 @@
 namespace events
 {
 
-using namespace phosphor::logging;
-
 /** @brief Function required by Cereal to perform serialization.
  *  @tparam Archive - Cereal archive type (binary in our case).
  *  @param[in] archive - reference to Cereal archive.
@@ -85,7 +83,7 @@
     }
     catch (const cereal::Exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Failed to deserialize: {ERROR}", "ERROR", e);
         std::error_code ec;
         fs::remove(path, ec);
         return false;
diff --git a/src/method.hpp b/src/method.hpp
index db37d24..715be8f 100644
--- a/src/method.hpp
+++ b/src/method.hpp
@@ -2,7 +2,7 @@
 
 #include "callback.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <experimental/tuple>
 #include <string>
@@ -17,8 +17,6 @@
 namespace detail
 {
 
-using namespace phosphor::logging;
-
 /** @class CallDBusMethod
  *  @brief Provide explicit call forwarding to
  *     DBusInterface::callMethodNoReply.
@@ -40,14 +38,10 @@
         }
         catch (const sdbusplus::exception::exception& e)
         {
-            // clang-format off
-            log<level::ERR>("Unable to call DBus method",
-                            entry("BUS=%s", bus.c_str(),
-                                  "PATH=%s", path.c_str(),
-                                  "IFACE=%s", iface.c_str(),
-                                  "METHOD=%s", method.c_str(),
-                                  "ERROR=%s", e.what()));
-            // clang-format on
+            lg2::error(
+                "Unable to call DBus method: {ERROR}. {BUS}, {PATH}, {INTF}, {METHOD}",
+                "ERROR", e, "BUS", bus, "PATH", path, "INTF", iface, "METHOD",
+                method);
         }
     }
 };
diff --git a/src/resolve_errors.cpp b/src/resolve_errors.cpp
index b48ca4f..fd5be34 100644
--- a/src/resolve_errors.cpp
+++ b/src/resolve_errors.cpp
@@ -17,7 +17,7 @@
 
 #include "sdbusplus.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 namespace phosphor
 {
@@ -32,7 +32,6 @@
 constexpr auto ENDPOINTS_PROPERTY = "endpoints";
 constexpr auto RESOLVED_PROPERTY = "Resolved";
 
-using namespace phosphor::logging;
 using EndpointList = std::vector<std::string>;
 using EndpointsProperty = std::variant<EndpointList>;
 
@@ -70,9 +69,8 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Failed getting callout fault associations",
-                        entry("CALLOUT=%s", callout.c_str()),
-                        entry("ERROR=%s", e.what()));
+        lg2::error("Failed getting callout fault associations: {ERROR}, {PATH}",
+                   "ERROR", e, "PATH", callout);
     }
 }
 
@@ -98,16 +96,15 @@
 
         if (response.is_method_error())
         {
-            log<level::ERR>(
-                "Failed to set Resolved property on an error log entry",
-                entry("ENTRY=%s", logEntry.c_str()));
+            lg2::error(
+                "Failed to set Resolved property on an error log entry: {ENTRY}",
+                "ENTRY", logEntry);
         }
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Unable to resolve error log entry",
-                        entry("ENTRY=%s", logEntry.c_str()),
-                        entry("ERROR=%s", e.what()));
+        lg2::error("Unable to resolve error log entry {ENTRY}: {ERROR}",
+                   "ENTRY", logEntry, "ERROR", e);
     }
 }
 
diff --git a/src/sdbusplus.hpp b/src/sdbusplus.hpp
index 1ff38a8..1e0b978 100644
--- a/src/sdbusplus.hpp
+++ b/src/sdbusplus.hpp
@@ -2,7 +2,6 @@
 
 #include "data_types.hpp"
 
-#include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/bus/match.hpp>
 #include <sdbusplus/exception.hpp>
@@ -19,8 +18,6 @@
 namespace monitoring
 {
 
-using namespace phosphor::logging;
-
 /** @class SDBusPlus
  *  @brief DBus access delegate implementation for sdbusplus.
  */
diff --git a/src/snmp_trap.cpp b/src/snmp_trap.cpp
index 6b4e808..c9e85b7 100644
--- a/src/snmp_trap.cpp
+++ b/src/snmp_trap.cpp
@@ -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 <snmp.hpp>
 #include <snmp_notification.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
@@ -13,7 +13,6 @@
 {
 namespace monitoring
 {
-using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Logging::server;
 using namespace phosphor::network::snmp;
 using InternalFailure =
@@ -50,13 +49,10 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::INFO>(
-            "Failed to send SNMP trap",
-            phosphor::logging::entry("ERROR_ID=%d", errorID),
-            phosphor::logging::entry("TIMESTAMP=%llu", timestamp),
-            phosphor::logging::entry("SEVERITY=%s",
-                                     convertForMessage(sev).c_str()),
-            phosphor::logging::entry("MESSAGE=%s", message.c_str()));
+        lg2::error(
+            "Failed to send SNMP trap: {ERROR}, ERROR_ID = {EID}, TIMESTAMP = {TSP}, SEVERITY = {SEVERITY}, MESSAGE = {MSG}",
+            "ERROR", e, "EID", errorID, "TSP", timestamp, "SEVERITY",
+            convertForMessage(sev), "MSG", message);
     }
 }
 } // namespace monitoring