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: I151fc489a93ec7f513411aea2f0b61829bc808f6
diff --git a/snmp_util.cpp b/snmp_util.cpp
index d0c8133..9f235d8 100644
--- a/snmp_util.cpp
+++ b/snmp_util.cpp
@@ -6,7 +6,7 @@
 #include <netdb.h>
 
 #include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <string>
 
@@ -30,8 +30,7 @@
 
     if (reply.is_method_error())
     {
-        log<level::ERR>("Failed to get managed objects",
-                        entry("PATH=%s", objPath.c_str()));
+        lg2::error("Failed to get managed objects: {PATH}", "PATH", objPath);
         elog<InternalFailure>();
     }
 
@@ -54,8 +53,8 @@
     auto result = getaddrinfo(address.c_str(), NULL, &hints, &addr);
     if (result)
     {
-        log<level::ERR>("getaddrinfo failed",
-                        entry("ADDRESS=%s", address.c_str()));
+        lg2::error("getaddrinfo failed {ADDRESS}: {RC}", "ADDRESS", address,
+                   "RC", result);
         elog<InternalFailure>();
     }
 
@@ -67,8 +66,8 @@
                          sizeof(ipaddress), NULL, 0, NI_NUMERICHOST);
     if (result)
     {
-        log<level::ERR>("getnameinfo failed",
-                        entry("ADDRESS=%s", address.c_str()));
+        lg2::error("getnameinfo failed {ADDRESS}: {RC}", "ADDRESS", address,
+                   "RC", result);
         elog<InternalFailure>();
     }
 
@@ -76,8 +75,8 @@
     int isValid = inet_pton(AF_INET, ipaddress, buf);
     if (isValid < 0)
     {
-        log<level::ERR>("Invalid address",
-                        entry("ADDRESS=%s", address.c_str()));
+        lg2::error("Invalid address {ADDRESS}: {RC}", "ADDRESS", address, "RC",
+                   isValid);
         elog<InternalFailure>();
     }
     if (isValid == 0)
@@ -85,8 +84,8 @@
         int isValid6 = inet_pton(AF_INET6, ipaddress, buf);
         if (isValid6 < 1)
         {
-            log<level::ERR>("Invalid address",
-                            entry("ADDRESS=%s", address.c_str()));
+            lg2::error("Invalid address {ADDRESS}: {RC}", "ADDRESS", address,
+                       "RC", isValid);
             elog<InternalFailure>();
         }
     }
@@ -135,7 +134,7 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>(e.what());
+            lg2::error("Invalid address: {ERROR}", "ERROR", e);
         }
     }
     return managers;