convert ipmid-new.cpp to use lg2

Change-Id: I0ebb51a11032c5925c0f2c2f949dd064bc5a8673
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/ipmid-new.cpp b/ipmid-new.cpp
index 9e12897..a34b581 100644
--- a/ipmid-new.cpp
+++ b/ipmid-new.cpp
@@ -28,7 +28,7 @@
 #include <ipmid/message.hpp>
 #include <ipmid/oemrouter.hpp>
 #include <ipmid/types.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/asio/connection.hpp>
 #include <sdbusplus/asio/object_server.hpp>
 #include <sdbusplus/asio/sd_event.hpp>
@@ -187,15 +187,15 @@
     if (!std::get<HandlerBase::ptr>(mapCmd) || std::get<int>(mapCmd) <= prio)
     {
         mapCmd = item;
-        log<level::DEBUG>("registered OEM Handler", entry("IANA=0x%x", iana),
-                          entry("CMD=0x%x", cmd),
-                          entry("netFnCmd=0x%x", netFnCmd));
+        lg2::debug("registered OEM Handler: NetFn/Cmd={NETFNCMD}", "IANA",
+                   lg2::hex, iana, "CMD", lg2::hex, cmd, "NETFNCMD", lg2::hex,
+                   netFnCmd);
         return true;
     }
 
-    log<level::WARNING>("could not register OEM Handler",
-                        entry("IANA=0x%x", iana), entry("CMD=0x%x", cmd),
-                        entry("netFnCmd=0x%x", netFnCmd));
+    lg2::warning("could not register OEM Handler: NetFn/Cmd={NETFNCMD}", "IANA",
+                 lg2::hex, iana, "CMD", lg2::hex, cmd, "NETFNCMD", lg2::hex,
+                 netFnCmd);
     return false;
 }
 
@@ -252,7 +252,8 @@
         // only return the filter response if the command is found
         if (filterResponse)
         {
-            log<level::DEBUG>("request has been filtered");
+            lg2::debug("request for NetFn/Cmd {NETFN}/{CMD} has been filtered",
+                       "NETFN", lg2::hex, keyCommon, "CMD", lg2::hex, cmd);
             return filterResponse;
         }
         HandlerTuple& chosen = cmdIter->second;
@@ -271,7 +272,9 @@
             // only return the filter response if the command is found
             if (filterResponse)
             {
-                log<level::DEBUG>("request has been filtered");
+                lg2::debug(
+                    "request for NetFn/Cmd {NETFN}/{CMD} has been filtered",
+                    "NETFN", lg2::hex, keyCommon, "CMD", lg2::hex, cmd);
                 return filterResponse;
             }
             HandlerTuple& chosen = cmdIter->second;
@@ -312,7 +315,7 @@
     }
     auto iana = static_cast<Iana>(bytes);
 
-    log<level::DEBUG>("unpack IANA", entry("IANA=0x%x", iana));
+    lg2::debug("unpack IANA {IANA}", "IANA", lg2::hex, iana);
 
     message::Response::ptr response = executeIpmiCommandCommon(oemHandlerMap,
                                                                iana, request);
@@ -365,8 +368,8 @@
                const std::string& nameOwner) {
         if (ec)
         {
-            log<level::ERR>("Error getting dbus owner",
-                            entry("INTERFACE=%s", name.c_str()));
+            lg2::error("Error getting dbus owner for {INTERFACE}", "INTERFACE",
+                       name);
             return;
         }
         // start after ipmiDbusChannelPrefix (after the '.')
@@ -375,14 +378,13 @@
         {
             uint8_t channel = getChannelByName(chName);
             uniqueNameToChannelNumber[nameOwner] = channel;
-            log<level::INFO>("New interface mapping",
-                             entry("INTERFACE=%s", name.c_str()),
-                             entry("CHANNEL=%u", channel));
+            lg2::info("New interface mapping: {INTERFACE} -> channel {CHANNEL}",
+                      "INTERFACE", name, "CHANNEL", channel);
         }
         catch (const std::exception& e)
         {
-            log<level::INFO>("Failed interface mapping, no such name",
-                             entry("INTERFACE=%s", name.c_str()));
+            lg2::info("Failed interface mapping, no such name: {INTERFACE}",
+                      "INTERFACE", name);
         }
     },
         "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetNameOwner",
@@ -396,7 +398,8 @@
                      std::vector<std::string> busNames) {
         if (ec)
         {
-            log<level::ERR>("Error getting dbus names");
+            lg2::error("Error getting dbus names: {ERROR}", "ERROR",
+                       ec.message());
             std::exit(EXIT_FAILURE);
             return;
         }
@@ -445,14 +448,13 @@
         {
             uint8_t channel = getChannelByName(chName);
             uniqueNameToChannelNumber[newOwner] = channel;
-            log<level::INFO>("New interface mapping",
-                             entry("INTERFACE=%s", name.c_str()),
-                             entry("CHANNEL=%u", channel));
+            lg2::info("New interface mapping: {INTERFACE} -> channel {CHANNEL}",
+                      "INTERFACE", name, "CHANNEL", channel);
         }
         catch (const std::exception& e)
         {
-            log<level::INFO>("Failed interface mapping, no such name",
-                             entry("INTERFACE=%s", name.c_str()));
+            lg2::info("Failed interface mapping, no such name: {INTERFACE}",
+                      "INTERFACE", name);
         }
     }
 };
@@ -503,9 +505,10 @@
     if (channel == invalidChannel)
     {
         // unknown sender channel; refuse to service the request
-        log<level::ERR>("ERROR determining source IPMI channel",
-                        entry("SENDER=%s", sender.c_str()),
-                        entry("NETFN=0x%X", netFn), entry("CMD=0x%X", cmd));
+        lg2::error("ERROR determining source IPMI channel from "
+                   "{SENDER} NetFn/Cmd {NETFN}/{CMD}",
+                   "SENDER", sender, "NETFN", lg2::hex, netFn, "CMD", lg2::hex,
+                   cmd);
         return dbusResponse(ipmi::ccDestinationUnavailable);
     }
 
@@ -525,9 +528,10 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>("ERROR determining IPMI session credentials",
-                            entry("CHANNEL=%u", channel),
-                            entry("NETFN=0x%X", netFn), entry("CMD=0x%X", cmd));
+            lg2::error("ERROR determining IPMI session credentials on "
+                       "channel {CHANNEL} for userid {USERID}",
+                       "CHANNEL", channel, "USERID", userId, "NETFN", lg2::hex,
+                       netFn, "CMD", lg2::hex, cmd);
             return dbusResponse(ipmi::ccUnspecifiedError);
         }
     }
@@ -562,13 +566,11 @@
         }
     }
     // check to see if the requested priv/username is valid
-    log<level::DEBUG>("Set up ipmi context", entry("SENDER=%s", sender.c_str()),
-                      entry("NETFN=0x%X", netFn), entry("LUN=0x%X", lun),
-                      entry("CMD=0x%X", cmd), entry("CHANNEL=%u", channel),
-                      entry("USERID=%u", userId),
-                      entry("SESSIONID=0x%X", sessionId),
-                      entry("PRIVILEGE=%u", static_cast<uint8_t>(privilege)),
-                      entry("RQSA=%x", rqSA));
+    lg2::debug("Set up ipmi context: Ch:NetFn/Cmd={CHANNEL}:{NETFN}/{CMD}",
+               "SENDER", sender, "NETFN", lg2::hex, netFn, "LUN", lg2::hex, lun,
+               "CMD", lg2::hex, cmd, "CHANNEL", channel, "USERID", userId,
+               "SESSIONID", lg2::hex, sessionId, "PRIVILEGE",
+               static_cast<uint8_t>(privilege), "RQSA", lg2::hex, rqSA);
 
     auto ctx = std::make_shared<ipmi::Context>(getSdBus(), netFn, lun, cmd,
                                                channel, userId, sessionId,
@@ -602,30 +604,26 @@
      */
     explicit IpmiProvider(const char* fname) : addr(nullptr), name(fname)
     {
-        log<level::DEBUG>("Open IPMI provider library",
-                          entry("PROVIDER=%s", name.c_str()));
+        lg2::debug("Open IPMI provider library: {PROVIDER}", "PROVIDER", name);
         try
         {
             addr = dlopen(name.c_str(), RTLD_NOW);
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>("ERROR opening IPMI provider",
-                            entry("PROVIDER=%s", name.c_str()),
-                            entry("ERROR=%s", e.what()));
+            lg2::error("ERROR opening IPMI provider {PROVIDER}: {ERROR}",
+                       "PROVIDER", name, "ERROR", e);
         }
         catch (...)
         {
             const char* what = currentExceptionType();
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "ERROR opening IPMI provider",
-                entry("PROVIDER=%s", name.c_str()), entry("ERROR=%s", what));
+            lg2::error("ERROR opening IPMI provider {PROVIDER}: {ERROR}",
+                       "PROVIDER", name, "ERROR", what);
         }
         if (!isOpen())
         {
-            log<level::ERR>("ERROR opening IPMI provider",
-                            entry("PROVIDER=%s", name.c_str()),
-                            entry("ERROR=%s", dlerror()));
+            lg2::error("ERROR opening IPMI provider {PROVIDER}: {ERROR}",
+                       "PROVIDER", name, "ERROR", dlerror());
         }
     }
 
@@ -675,8 +673,7 @@
     for (auto& lib : libs)
     {
 #ifdef __IPMI_DEBUG__
-        log<level::DEBUG>("Registering handler",
-                          entry("HANDLER=%s", lib.c_str()));
+        lg2::debug("Registering handler {HANDLER}", "HANDLER", lib);
 #endif
         handles.emplace_front(lib.c_str());
     }
@@ -794,10 +791,10 @@
                                response->payload.raw);
         if (ec)
         {
-            log<level::ERR>("Failed to send response to requestor",
-                            entry("ERROR=%s", ec.message().c_str()),
-                            entry("SENDER=%s", dest),
-                            entry("NETFN=0x%X", netFn), entry("CMD=0x%X", cmd));
+            lg2::error(
+                "Failed to send response to requestor ({NETFN}/{CMD}): {ERROR}",
+                "ERROR", ec.message(), "SENDER", dest, "NETFN", lg2::hex, netFn,
+                "CMD", lg2::hex, cmd);
         }
     });
 }
@@ -874,8 +871,7 @@
     // set up boost::asio signal handling
     std::function<SignalResponse(int)> stopAsioRunLoop =
         [&io, &exitCode](int signalNumber) {
-        log<level::INFO>("Received signal; quitting",
-                         entry("SIGNAL=%d", signalNumber));
+        lg2::info("Received signal {SIGNAL}; quitting", "SIGNAL", signalNumber);
         io->stop();
         exitCode = signalNumber;
         return SignalResponse::breakExecution;