PHAL: added createErrorPEL wrapper function

Refactored createBootErrorPEL to support callout and
additional data information as optional parameter to
support diffrent types of PEL creation.

Also renamed createBootErrorPEL -> createErrorPEL.

Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Change-Id: Iee6e356740179caf6486a2750cf30278240a5785
diff --git a/extensions/phal/create_pel.cpp b/extensions/phal/create_pel.cpp
index b3fdd4e..6ba71d0 100644
--- a/extensions/phal/create_pel.cpp
+++ b/extensions/phal/create_pel.cpp
@@ -32,7 +32,8 @@
 constexpr auto loggingInterface = "xyz.openbmc_project.Logging.Create";
 constexpr auto opLoggingInterface = "org.open_power.Logging.PEL";
 
-void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData)
+void createErrorPEL(const std::string& event, const json& calloutData,
+                    const FFDCData& ffdcData)
 {
     std::map<std::string, std::string> additionalData;
     auto bus = sdbusplus::bus::new_default();
@@ -57,8 +58,6 @@
                             static_cast<uint8_t>(0xCA),
                             static_cast<uint8_t>(0x01), ffdcFile.getFileFD()));
 
-        static constexpr auto bootErrorMessage =
-            "org.open_power.PHAL.Error.Boot";
         std::string service =
             util::getService(bus, loggingObjectPath, loggingInterface);
         auto method =
@@ -68,16 +67,16 @@
             sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
                 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
                     Error);
-        method.append(bootErrorMessage, level, additionalData, pelCalloutInfo);
+        method.append(event, level, additionalData, pelCalloutInfo);
         auto resp = bus.call(method);
     }
     catch (const sdbusplus::exception::exception& e)
     {
-        log<level::ERR>("D-Bus call exception",
-                        entry("OBJPATH=%s", loggingObjectPath),
-                        entry("INTERFACE=%s", loggingInterface),
-                        entry("EXCEPTION=%s", e.what()));
-
+        log<level::ERR>(
+            fmt::format("D-Bus call exception",
+                        "OBJPATH={}, INTERFACE={}, event={}, EXCEPTION={}",
+                        loggingObjectPath, loggingInterface, event, e.what())
+                .c_str());
         throw std::runtime_error(
             "Error in invoking D-Bus logging create interface");
     }
diff --git a/extensions/phal/create_pel.hpp b/extensions/phal/create_pel.hpp
index 5c780eb..481417b 100644
--- a/extensions/phal/create_pel.hpp
+++ b/extensions/phal/create_pel.hpp
@@ -17,12 +17,14 @@
 using namespace openpower::phal;
 
 /**
- * @brief Create boot error PEL
+ * @brief Create PEL with additional parameters and callout
  *
- * @param[in] ffdcData - failure data to append to PEL
+ * @param[in] event - the event type
  * @param[in] calloutData - callout data to append to PEL
+ * @param[in] ffdcData - failure data to append to PEL
  */
-void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);
+void createErrorPEL(const std::string& event, const json& calloutData = {},
+                    const FFDCData& ffdcData = {});
 
 /**
  * @brief Create SBE boot error PEL and return id
diff --git a/extensions/phal/phal_error.cpp b/extensions/phal/phal_error.cpp
index 531379d..0a5246e 100644
--- a/extensions/phal/phal_error.cpp
+++ b/extensions/phal/phal_error.cpp
@@ -501,9 +501,8 @@
                 // Considering a element having higher priority than b element
                 return true;
             });
-
-        openpower::pel::createBootErrorPEL(pelAdditionalData,
-                                           jsonCalloutDataList);
+        openpower::pel::createErrorPEL("org.open_power.PHAL.Error.Boot",
+                                       jsonCalloutDataList, pelAdditionalData);
     }
     catch (const std::exception& ex)
     {