ipmid: switch to lg2

Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I838587b2d564f3c00b78ce37e175d7e8ace51142
diff --git a/include/ipmid/handler.hpp b/include/ipmid/handler.hpp
index 62fcbe9..77f6670 100644
--- a/include/ipmid/handler.hpp
+++ b/include/ipmid/handler.hpp
@@ -20,6 +20,7 @@
 #include <boost/callable_traits.hpp>
 #include <ipmid/api-types.hpp>
 #include <ipmid/message.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <phosphor-logging/log.hpp>
 #include <user_channel/channel_layer.hpp>
 
@@ -266,21 +267,18 @@
         }
         catch (const HandlerException& e)
         {
-            phosphor::logging::log<phosphor::logging::level::INFO>(
-                "Handler produced exception",
-                phosphor::logging::entry("CC=%x", e.code()),
-                phosphor::logging::entry("EXCEPTION=%s", e.what()),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::info("Handler produced exception, NetFn: {NETFN}, "
+                      "Cmd: {CMD}: {ERROR}",
+                      "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                      request->ctx->cmd, "ERROR", e);
             return errorResponse(request, e.code());
         }
         catch (const std::exception& e)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Handler failed to catch exception",
-                phosphor::logging::entry("EXCEPTION=%s", e.what()),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::error("Handler failed to catch exception, NetFn: {NETFN}, "
+                       "Cmd: {CMD}: {ERROR}",
+                       "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                       request->ctx->cmd, "ERROR", e);
             return errorResponse(request, ccUnspecifiedError);
         }
         catch (const HandlerCompletion& c)
@@ -290,11 +288,10 @@
         catch (...)
         {
             const char* what = currentExceptionType();
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Handler failed to catch exception",
-                phosphor::logging::entry("EXCEPTION=%s", what),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::error("Handler failed to catch exception, NetFn: {NETFN}, "
+                       "Cmd: {CMD}: {ERROR}",
+                       "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                       request->ctx->cmd, "ERROR", what);
             return errorResponse(request, ccUnspecifiedError);
         }
 
@@ -367,21 +364,18 @@
         }
         catch (const HandlerException& e)
         {
-            phosphor::logging::log<phosphor::logging::level::INFO>(
-                "Legacy Handler produced exception",
-                phosphor::logging::entry("CC=%x", e.code()),
-                phosphor::logging::entry("EXCEPTION=%s", e.what()),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::info("Legacy Handler produced exception, NetFn: {NETFN}, "
+                      "Cmd: {CMD}: {ERROR}",
+                      "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                      request->ctx->cmd, "ERROR", e);
             return errorResponse(request, e.code());
         }
         catch (const std::exception& e)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Legacy Handler failed to catch exception",
-                phosphor::logging::entry("EXCEPTION=%s", e.what()),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::error("Legacy Handler failed to catch exception, "
+                       "NetFn: {NETFN}, Cmd: {CMD}: {ERROR}",
+                       "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                       request->ctx->cmd, "ERROR", e);
             return errorResponse(request, ccUnspecifiedError);
         }
         catch (const HandlerCompletion& c)
@@ -391,11 +385,10 @@
         catch (...)
         {
             const char* what = currentExceptionType();
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Handler failed to catch exception",
-                phosphor::logging::entry("EXCEPTION=%s", what),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::error("Handler failed to catch exception, NetFn: {NETFN}, "
+                       "Cmd: {CMD}: {ERROR}",
+                       "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                       request->ctx->cmd, "ERROR", what);
             return errorResponse(request, ccUnspecifiedError);
         }
         response->cc = ccRet;
@@ -457,21 +450,18 @@
         }
         catch (const HandlerException& e)
         {
-            phosphor::logging::log<phosphor::logging::level::INFO>(
-                "Legacy OEM Handler produced exception",
-                phosphor::logging::entry("CC=%x", e.code()),
-                phosphor::logging::entry("EXCEPTION=%s", e.what()),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::info("Legacy OEM Handler produced exception, NetFn: {NETFN}, "
+                      "Cmd: {CMD}: {ERROR}",
+                      "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                      request->ctx->cmd, "ERROR", e);
             return errorResponse(request, e.code());
         }
         catch (const std::exception& e)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Legacy OEM Handler failed to catch exception",
-                phosphor::logging::entry("EXCEPTION=%s", e.what()),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::error("Legacy OEM Handler failed to catch exception, "
+                       "NetFn: {NETFN}, Cmd: {CMD}: {ERROR}",
+                       "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                       request->ctx->cmd, "ERROR", e);
             return errorResponse(request, ccUnspecifiedError);
         }
         catch (const HandlerCompletion& c)
@@ -481,11 +471,10 @@
         catch (...)
         {
             const char* what = currentExceptionType();
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Handler failed to catch exception",
-                phosphor::logging::entry("EXCEPTION=%s", what),
-                phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
-                phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+            lg2::error("Legacy failed to catch exception, NetFn: {NETFN}, "
+                       "Cmd: {CMD}: {ERROR}",
+                       "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+                       request->ctx->cmd, "ERROR", what);
             return errorResponse(request, ccUnspecifiedError);
         }
         response->cc = ccRet;
diff --git a/include/ipmid/message.hpp b/include/ipmid/message.hpp
index 5264112..7a709e4 100644
--- a/include/ipmid/message.hpp
+++ b/include/ipmid/message.hpp
@@ -19,7 +19,7 @@
 #include <ipmid/api-types.hpp>
 #include <ipmid/message/types.hpp>
 #include <ipmid/types.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/asio/connection.hpp>
 
 #include <algorithm>
@@ -119,11 +119,12 @@
 
     ~Payload()
     {
-        using namespace phosphor::logging;
         if (raw.size() != 0 && std::uncaught_exceptions() == 0 && !trailingOk &&
             !unpackCheck && !unpackError)
         {
-            log<level::ERR>("Failed to check request for full unpack");
+            lg2::error(
+                "Failed to check request for full unpack: raw size: {RAW_SIZE}",
+                "RAW_SIZE", raw.size());
         }
     }
 
diff --git a/include/ipmid/message/pack.hpp b/include/ipmid/message/pack.hpp
index 5ca94b6..407c35f 100644
--- a/include/ipmid/message/pack.hpp
+++ b/include/ipmid/message/pack.hpp
@@ -16,6 +16,7 @@
 #pragma once
 
 #include <ipmid/message/types.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <phosphor-logging/log.hpp>
 
 #include <array>
@@ -120,8 +121,7 @@
         uint8_t len;
         if (t.length() > std::numeric_limits<decltype(len)>::max())
         {
-            using namespace phosphor::logging;
-            log<level::ERR>("long string truncated on IPMI message pack");
+            lg2::error("long string truncated on IPMI message pack");
             return 1;
         }
         len = static_cast<uint8_t>(t.length());