oem-ibm: Improving logs (lg2)

This commit corrects the severity level of logs and also formats the
message string, fixing the ill-defined message string of the logs as
mentioned in the anti-pattern document [1]. Additionally, based on the
requirement this commit adds more debug information to logs.

[1]: https://github.com/openbmc/docs/blob/master/anti-patterns.md#ill-defined-data-structuring-in-lg2-message-strings

Change-Id: I24ca21de35d5a1a9b3cc64b28a149e4c213055f9
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/oem/ibm/libpldmresponder/inband_code_update.cpp b/oem/ibm/libpldmresponder/inband_code_update.cpp
index e4ab130..71b6ec3 100644
--- a/oem/ibm/libpldmresponder/inband_code_update.cpp
+++ b/oem/ibm/libpldmresponder/inband_code_update.cpp
@@ -93,9 +93,8 @@
     }
     catch (const std::exception& e)
     {
-        error(
-            "failed to set the next boot side to {OBJ_PATH} ERROR={ERR_EXCEP}",
-            "OBJ_PATH", objPath.c_str(), "ERR_EXCEP", e.what());
+        error("Failed to set the next boot side to {PATH} , error - {ERROR}",
+              "PATH", objPath, "ERROR", e);
         return PLDM_ERROR;
     }
     return PLDM_SUCCESS;
@@ -118,10 +117,9 @@
     catch (const std::exception& e)
     {
         error(
-            "Failed To set RequestedApplyTime property, OBJ_PATH={OBJ_PATH}, INTERFACE={INTERFACE}, PROP_NAME={PROP_NAME}, ERROR={ERR_EXCEP}",
-            "OBJ_PATH", dbusMapping.objectPath, "INTERFACE",
-            dbusMapping.interface, "PROP_NAME", dbusMapping.propertyName,
-            "ERR_EXCEP", e.what());
+            "Failed to set property '{PROPERTY}' at path '{PATH}' and interface '{INTERFACE}', error - {ERROR}",
+            "PATH", dbusMapping.objectPath, "INTERFACE", dbusMapping.interface,
+            "PROPERTY", dbusMapping.propertyName, "ERROR", e);
         rc = PLDM_ERROR;
     }
     return rc;
@@ -144,10 +142,9 @@
     catch (const std::exception& e)
     {
         error(
-            "Failed To set RequestedActivation property, OBJ_PATH={OBJ_PATH}, INTERFACE={INTERFACE}, PROP_NAME={PROP_NAME}, ERROR={ERR_EXCEP}",
-            "OBJ_PATH", dbusMapping.objectPath, "INTERFACE",
-            dbusMapping.interface, "PROP_NAME", dbusMapping.propertyName,
-            "ERR_EXCEP", e.what());
+            "Failed to set property {PROPERTY} at path '{PATH}' and interface '{INTERFACE}', error - {ERROR}",
+            "PATH", dbusMapping.objectPath, "INTERFACE", dbusMapping.interface,
+            "PROPERTY", dbusMapping.propertyName, "ERROR", e);
         rc = PLDM_ERROR;
     }
     return rc;
@@ -193,8 +190,8 @@
     catch (const std::exception& e)
     {
         error(
-            "failed to make a d-bus call to Object Mapper Association, ERROR={ERR_EXCEP}",
-            "ERR_EXCEP", e.what());
+            "Failed to make a d-bus call to Object Mapper Association, error - {ERROR}",
+            "ERROR", e);
         return;
     }
 
@@ -293,6 +290,7 @@
                         auto rc = setRequestedActivation();
                         if (rc != PLDM_SUCCESS)
                         {
+                            error("Could not set Requested Activation");
                             CodeUpdateState state = CodeUpdateState::FAIL;
                             setCodeUpdateProgress(false);
                             auto sensorId = getFirmwareUpdateSensor();
@@ -300,7 +298,6 @@
                                 sensorId, PLDM_STATE_SENSOR_STATE, 0,
                                 uint8_t(state),
                                 uint8_t(CodeUpdateState::START));
-                            error("could not set RequestedActivation");
                         }
                         break;
                     }
@@ -308,9 +305,9 @@
                 catch (const sdbusplus::exception_t& e)
                 {
                     error(
-                        "Error in getting Activation status,ERROR= {ERR_EXCEP}, INTERFACE={IMG_INTERFACE}, OBJECT PATH={OBJ_PATH}",
-                        "ERR_EXCEP", e.what(), "IMG_INTERFACE", imageInterface,
-                        "OBJ_PATH", imageObjPath);
+                        "Failed to get activation status for interface '{INTERFACE}' and object path '{PATH}', error - {ERROR}",
+                        "ERROR", e, "INTERFACE", imageInterface, "PATH",
+                        imageObjPath);
                 }
             }
         }
@@ -341,8 +338,7 @@
 {
     if (!fs::is_directory(dirPath))
     {
-        error("The directory does not exist, dirPath = {DIR_PATH}", "DIR_PATH",
-              dirPath.c_str());
+        error("The directory '{PATH}' does not exist", "PATH", dirPath);
         return;
     }
     for (const auto& iter : fs::directory_iterator(dirPath))
@@ -380,9 +376,8 @@
     catch (const std::exception& e)
     {
         error(
-            "Failed to delete image, OBJ_PATH={OBJ_PATH}, INTERFACE={INTERFACE}, ERROR={ERR_EXCEP}",
-            "OBJ_PATH", SW_OBJ_PATH, "INTERFACE", DELETE_INTF, "ERR_EXCEP",
-            e.what());
+            "Failed to delete image at path '{PATH}' and interface '{INTERFACE}', error - {ERROR}",
+            "PATH", SW_OBJ_PATH, "INTERFACE", DELETE_INTF, "ERROR", e);
         return;
     }
 }
@@ -477,7 +472,7 @@
     std::ifstream ifs(filePath, std::ios::in | std::ios::binary);
     if (!ifs)
     {
-        error("ifstream open error: {DIR_PATH}", "DIR_PATH", filePath.c_str());
+        error("Failed to opening file '{FILE}' ifstream", "PATH", filePath);
         return PLDM_ERROR;
     }
     ifs.seekg(0);
@@ -496,7 +491,7 @@
     constexpr auto magicNumber = 0x0222;
     if (htons(header.magicNumber) != magicNumber)
     {
-        error("Invalid magic number: {DIR_PATH}", "DIR_PATH", filePath.c_str());
+        error("Invalid magic number for file '{PATH}'", "PATH", filePath);
         ifs.close();
         return PLDM_ERROR;
     }
@@ -609,7 +604,8 @@
         }
         else if (nextPid < 0)
         {
-            error("Error occurred during fork. ERROR={ERR}", "ERR", errno);
+            error("Failure occurred during fork, error number - {ERROR_NUM}",
+                  "ERROR_NUM", errno);
             exit(EXIT_FAILURE);
         }
 
@@ -622,21 +618,23 @@
         int status;
         if (waitpid(pid, &status, 0) < 0)
         {
-            error("Error occurred during waitpid. ERROR={ERR}", "ERR", errno);
+            error("Error occurred during waitpid, error number - {ERROR_NUM}",
+                  "ERROR_NUM", errno);
 
             return PLDM_ERROR;
         }
         else if (WEXITSTATUS(status) != 0)
         {
             error(
-                "Failed to execute the assembling of the image. STATUS={IMG_STATUS}",
+                "Failed to execute the assembling of the image, status is {IMG_STATUS}",
                 "IMG_STATUS", status);
             return PLDM_ERROR;
         }
     }
     else
     {
-        error("Error occurred during fork. ERROR={ERR}", "ERR", errno);
+        error("Error occurred during fork, error number - {ERROR_NUM}}",
+              "ERROR_NUM", errno);
         return PLDM_ERROR;
     }