PEL: Use lg2 in Registry class

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I5a7499843887afba545688d24876d4308384dc61
diff --git a/extensions/openpower-pels/registry.cpp b/extensions/openpower-pels/registry.cpp
index a96f661..4dc1f0b 100644
--- a/extensions/openpower-pels/registry.cpp
+++ b/extensions/openpower-pels/registry.cpp
@@ -19,7 +19,7 @@
 #include "pel_types.hpp"
 #include "pel_values.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <fstream>
 
@@ -32,7 +32,6 @@
 
 namespace pv = pel_values;
 namespace fs = std::filesystem;
-using namespace phosphor::logging;
 
 constexpr auto debugFilePath = "/etc/phosphor-logging/";
 
@@ -46,8 +45,8 @@
     if (ss == pv::subsystemValues.end())
     {
         // Schema validation should be catching this.
-        log<level::ERR>("Invalid subsystem name used in message registry",
-                        entry("SUBSYSTEM=%s", subsystemName.c_str()));
+        lg2::error("Invalid subsystem name used in message registry: {SUBSYS}",
+                   "SUBSYS", subsystemName);
 
         throw std::runtime_error("Invalid subsystem used in message registry");
     }
@@ -61,8 +60,8 @@
     if (s == pv::severityValues.end())
     {
         // Schema validation should be catching this.
-        log<level::ERR>("Invalid severity name used in message registry",
-                        entry("SEVERITY=%s", severityName.c_str()));
+        lg2::error("Invalid severity name used in message registry: {SEV}",
+                   "SEV", severityName);
 
         throw std::runtime_error("Invalid severity used in message registry");
     }
@@ -116,8 +115,9 @@
         if (s == pv::actionFlagsValues.end())
         {
             // Schema validation should be catching this.
-            log<level::ERR>("Invalid action flag name used in message registry",
-                            entry("FLAG=%s", flag.c_str()));
+            lg2::error(
+                "Invalid action flag name used in message registry: {FLAG}",
+                "FLAG", flag);
 
             throw std::runtime_error(
                 "Invalid action flag used in message registry");
@@ -134,8 +134,8 @@
     auto t = pv::findByName(eventTypeName, pv::eventTypeValues);
     if (t == pv::eventTypeValues.end())
     {
-        log<level::ERR>("Invalid event type used in message registry",
-                        entry("EVENT_TYPE=%s", eventTypeName.c_str()));
+        lg2::error("Invalid event type used in message registry: {TYPE}",
+                   "TYPE", eventTypeName);
 
         throw std::runtime_error("Invalid event type used in message registry");
     }
@@ -147,8 +147,8 @@
     auto s = pv::findByName(eventScopeName, pv::eventScopeValues);
     if (s == pv::eventScopeValues.end())
     {
-        log<level::ERR>("Invalid event scope used in registry",
-                        entry("EVENT_SCOPE=%s", eventScopeName.c_str()));
+        lg2::error("Invalid event scope used in registry: {SCOPE}", "SCOPE",
+                   eventScopeName);
 
         throw std::runtime_error(
             "Invalid event scope used in message registry");
@@ -162,10 +162,9 @@
     uint16_t reasonCode = strtoul(rc.c_str(), nullptr, 16);
     if (reasonCode == 0)
     {
-        log<phosphor::logging::level::ERR>(
-            "Invalid reason code in message registry",
-            entry("ERROR_NAME=%s", name.c_str()),
-            entry("REASON_CODE=%s", rc.c_str()));
+        lg2::error(
+            "Invalid reason code {RC} in message registry, error name = {ERROR}",
+            "RC", rc, "ERROR", name);
 
         throw std::runtime_error("Invalid reason code in message registry");
     }
@@ -179,10 +178,9 @@
     size_t type = strtoul(srcType.c_str(), nullptr, 16);
     if ((type == 0) || (srcType.size() != 2)) // 1 hex byte
     {
-        log<phosphor::logging::level::ERR>(
-            "Invalid SRC Type in message registry",
-            entry("ERROR_NAME=%s", name.c_str()),
-            entry("SRC_TYPE=%s", srcType.c_str()));
+        lg2::error(
+            "Invalid SRC Type {TYPE} in message registry, error name = {ERROR}",
+            "TYPE", srcType, "ERROR", name);
 
         throw std::runtime_error("Invalid SRC Type in message registry");
     }
@@ -223,10 +221,9 @@
 
         if (wordNum == 0)
         {
-            log<phosphor::logging::level::ERR>(
-                "Invalid SRC word number in message registry",
-                entry("ERROR_NAME=%s", name.c_str()),
-                entry("SRC_WORD_NUM=%s", num.c_str()));
+            lg2::error(
+                "Invalid SRC word number {NUM} in message registry, error name = {ERROR}",
+                "NUM", num, "ERROR", name);
 
             throw std::runtime_error("Invalid SRC word in message registry");
         }
@@ -265,10 +262,9 @@
         size_t num = std::strtoul(srcWordNum.c_str(), nullptr, 10);
         if (num == 0)
         {
-            log<phosphor::logging::level::ERR>(
-                "Invalid symptom ID field in message registry",
-                entry("ERROR_NAME=%s", name.c_str()),
-                entry("FIELD_NAME=%s", srcWordNum.c_str()));
+            lg2::error(
+                "Invalid symptom ID field {FIELD} in message registry, error name = {ERROR}",
+                "FIELD", field, "ERROR", name);
 
             throw std::runtime_error("Invalid symptom ID in message registry");
         }
@@ -304,8 +300,9 @@
         }
         else
         {
-            log<level::ERR>("Missing component ID field in message registry",
-                            entry("ERROR_NAME=%s", name.c_str()));
+            lg2::error(
+                "Missing component ID field in message registry, error name = {ERROR}",
+                "ERROR", name);
 
             throw std::runtime_error(
                 "Missing component ID field in message registry");
@@ -391,10 +388,10 @@
         std::string types;
         std::for_each(systemNames.begin(), systemNames.end(),
                       [&types](const auto& t) { types += t + '|'; });
-        log<level::WARNING>(
+        lg2::warning(
             "No matching system name entry or default system name entry "
-            " for PEL callout list",
-            entry("SYSTEMNAMES=%s", types.c_str()));
+            " for PEL callout list, names = {TYPES}",
+            "TYPES", types);
 
         throw std::runtime_error{
             "Could not find a CalloutList JSON for this error and system name"};
@@ -553,11 +550,10 @@
     if (!adValue)
     {
         // The AdditionalData did not contain the necessary key
-        log<level::WARNING>(
-            "The PEL message registry callouts JSON "
-            "said to use an AdditionalData key that isn't in the "
-            "AdditionalData event log property",
-            entry("ADNAME=%s\n", keyName.c_str()));
+        lg2::warning("The PEL message registry callouts JSON "
+                     "said to use an AdditionalData key that isn't in the "
+                     "AdditionalData event log property, key = {KEY}",
+                     "KEY", keyName);
         throw std::runtime_error{
             "Missing AdditionalData entry for this callout"};
     }
@@ -633,7 +629,7 @@
     }
     else
     {
-        log<level::ERR>("JournalCapture section not the right format");
+        lg2::error("JournalCapture section not the right format");
         throw std::runtime_error{"JournalCapture section not the right format"};
     }
 
@@ -786,8 +782,8 @@
         }
         catch (const std::exception& ex)
         {
-            log<level::ERR>("Found invalid message registry field",
-                            entry("ERROR=%s", ex.what()));
+            lg2::error("Found invalid message registry field. Error: {ERROR}",
+                       "ERROR", ex);
         }
     }
 
@@ -804,7 +800,7 @@
 
     if (fs::exists(debugFile))
     {
-        log<level::INFO>("Using debug PEL message registry");
+        lg2::info("Using debug PEL message registry");
         file.open(debugFile);
     }
     else
@@ -818,8 +814,8 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Error parsing message registry JSON",
-                        entry("JSON_ERROR=%s", e.what()));
+        lg2::error("Error parsing message registry JSON. Error: {ERROR}",
+                   "ERROR", e);
         return std::nullopt;
     }
     return registry;