PLDM: Implementing Phosphor-Logging/LG2 logging

This commit adds changes in PLDM for implementing
structured LG2 logging, thereby moving away from
std::cout/cerr practice of logging which are
output streams and not logging mechanism.

PLDM now can make use of lg2 features like accurate
CODE LINE Number and CODE_FUNCTION Name and better
detailing in json object values which can be used in
log tracking.

More detailed logging change:
https://gist.github.com/riyadixitagra/c251685c1ba84248181891f7bc282395

Tested:
Ran a power off, on, cycle, and reset-reload.

Change-Id: I0485035f15f278c3fd172f0581b053c1c37f3a5b
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/libpldmresponder/platform_state_effecter.hpp b/libpldmresponder/platform_state_effecter.hpp
index 1e3f3fd..3586d60 100644
--- a/libpldmresponder/platform_state_effecter.hpp
+++ b/libpldmresponder/platform_state_effecter.hpp
@@ -10,9 +10,13 @@
 #include <libpldm/platform.h>
 #include <libpldm/states.h>
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <cstdint>
 #include <map>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
@@ -53,7 +57,7 @@
                   PLDM_STATE_EFFECTER_PDR);
     if (stateEffecterPDRs.empty())
     {
-        std::cerr << "Failed to get record by PDR type\n";
+        error("Failed to get record by PDR type");
         return PLDM_PLATFORM_INVALID_EFFECTER_ID;
     }
 
@@ -73,9 +77,9 @@
             pdr->possible_states);
         if (compEffecterCnt > pdr->composite_effecter_count)
         {
-            std::cerr << "The requester sent wrong composite effecter"
-                      << " count for the effecter, EFFECTER_ID=" << effecterId
-                      << "COMP_EFF_CNT=" << compEffecterCnt << "\n";
+            error(
+                "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
+                "EFFECTER_ID", effecterId, "COMP_EFF_CNT", compEffecterCnt);
             return PLDM_ERROR_INVALID_DATA;
         }
         break;
@@ -101,12 +105,12 @@
             if (states->possible_states_size < bitfieldIndex ||
                 !(states->states[bitfieldIndex].byte & (1 << bit)))
             {
-                std::cerr << "Invalid state set value, EFFECTER_ID="
-                          << effecterId
-                          << " VALUE=" << stateField[currState].effecter_state
-                          << " COMPOSITE_EFFECTER_ID=" << currState
-                          << " DBUS_PATH=" << dbusMappings[currState].objectPath
-                          << "\n";
+                error(
+                    "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
+                    "EFFECTER_ID", effecterId, "EFFECTER_STATE",
+                    stateField[currState].effecter_state, "CURR_STATE",
+                    currState, "DBUS_OBJ_PATH",
+                    dbusMappings[currState].objectPath.c_str());
                 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
                 break;
             }
@@ -124,11 +128,12 @@
                 }
                 catch (const std::exception& e)
                 {
-                    std::cerr
-                        << "Error setting property, ERROR=" << e.what()
-                        << " PROPERTY=" << dbusMapping.propertyName
-                        << " INTERFACE=" << dbusMapping.interface << " PATH="
-                        << dbusMapping.objectPath << "\n";
+                    error(
+                        "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
+                        "ERR_EXCEP", e.what(), "DBUS_PROP",
+                        dbusMapping.propertyName, "DBUS_INTF",
+                        dbusMapping.interface, "DBUS_OBJ_PATH",
+                        dbusMapping.objectPath.c_str());
                     return PLDM_ERROR;
                 }
             }
@@ -143,7 +148,8 @@
     }
     catch (const std::out_of_range& e)
     {
-        std::cerr << "Unknown effecter ID : " << effecterId << e.what() << '\n';
+        error("Unknown effecter ID : {EFFECTER_ID} {ERR_EXCEP}", "EFFECTER_ID",
+              effecterId, "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }