Adding severity when reporting an error

Severity is part of the PEL User Header section, and is used
to specify the PEL severity. This commit adds an option to pass
severity parameter while logging PEL. This will help to classify PELs
based on their severity. The commit also maintains uniformity in
the PEL Error logged.

Tested: By creating the error logs(pel) in error scenarios.

Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
Change-Id: Ic084d49b8ffe9aaea2c36c9fefa95a10a9c1c3ec
diff --git a/common/types.hpp b/common/types.hpp
index 0c7514c..6f100c5 100644
--- a/common/types.hpp
+++ b/common/types.hpp
@@ -20,6 +20,18 @@
 using Response = std::vector<uint8_t>;
 using Command = uint8_t;
 
+enum PelSeverity
+{
+    Notice,
+    Informational,
+    Debug,
+    Warning,
+    Critical,
+    Emergency,
+    Alert,
+    Error
+};
+
 namespace dbus
 {
 
diff --git a/common/utils.cpp b/common/utils.cpp
index 076cd5c..7e43b49 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -448,7 +448,7 @@
     return response;
 }
 
-void reportError(const char* errorMsg)
+void reportError(const char* errorMsg, const Severity& sev)
 {
     auto& bus = pldm::utils::DBusHandler::getBus();
 
@@ -457,15 +457,19 @@
         using LoggingCreate =
             sdbusplus::client::xyz::openbmc_project::logging::Create<>;
 
+        std::string severity = "xyz.openbmc_project.Logging.Entry.Level.Error";
+
         using namespace sdbusplus::xyz::openbmc_project::Logging::server;
-        auto severity =
-            sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
-                sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
-                    Error);
         auto method = bus.new_method_call(LoggingCreate::default_service,
                                           LoggingCreate::instance_path,
                                           LoggingCreate::interface, "Create");
 
+        auto itr = sevMap.find(sev);
+        if (itr != sevMap.end())
+        {
+            severity = itr->second;
+        }
+
         std::map<std::string, std::string> addlData{};
         method.append(errorMsg, severity, addlData);
         bus.call_noreply(method, dbusTimeout);
diff --git a/common/utils.hpp b/common/utils.hpp
index 5f24322..e940265 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -32,6 +32,20 @@
 
 namespace pldm
 {
+using Severity = pldm::PelSeverity;
+
+// mapping of severity enum to severity interface
+static std::unordered_map<Severity, std::string> sevMap = {
+    {Severity::Informational,
+     "xyz.openbmc_project.Logging.Entry.Level.Informational"},
+    {Severity::Debug, "xyz.openbmc_project.Logging.Entry.Level.Debug"},
+    {Severity::Notice, "xyz.openbmc_project.Logging.Entry.Level.Notice"},
+    {Severity::Warning, "xyz.openbmc_project.Logging.Entry.Level.Warning"},
+    {Severity::Critical, "xyz.openbmc_project.Logging.Entry.Level.Critical"},
+    {Severity::Emergency, "xyz.openbmc_project.Logging.Entry.Level.Emergency"},
+    {Severity::Error, "xyz.openbmc_project.Logging.Entry.Level.Error"},
+    {Severity::Alert, "xyz.openbmc_project.Logging.Entry.Level.Alert"}};
+
 namespace utils
 {
 namespace fs = std::filesystem;
@@ -139,8 +153,11 @@
 /**
  *  @brief creates an error log
  *  @param[in] errorMsg - the error message
+ *  @param[in] sev - severity of the log
+ *
  */
-void reportError(const char* errorMsg);
+void reportError(const char* errorMsg,
+                 const PelSeverity& sev = pldm::PelSeverity::Error);
 
 /** @brief Convert any Decimal number to BCD
  *