Implementing Phosphor-Logging/LG2 logging

This commit introduces changes in the phosphor-debug-collector
repository to implement structured logging using the LG2
framework. The existing log calls in the repository,
have been replaced with LG2 logging, facilitates better
log tracking and troubleshooting by offering improved
detail in JSON object values.

Test:
- Created BMC dump
- Created system dump

Here is a example
{
	"_EXE" : "/tmp/phosphor-dump-manager",
	"_MACHINE_ID" : "f9ca96d99c7b4ba688556f632ffeff5d",
	"_CAP_EFFECTIVE" : "1ffffffffff",
	"LOG2_FMTMSG" : "Invalid Dump file name, FILENAME: {FILENAME}",
	"__CURSOR" : "s=721ae7a5b6ed43ec904f2bb03e3c0403;i=2a8d0;\
b=b372b9a5989e46bb8e62b33310e181ea;m=2c05fda2b;t=5fdf0684c1e70;x=1592f60584d6486c",
	"CODE_FUNC" : "void phosphor::dump::bmc::Manager::\
createEntry(const std::filesystem::__cxx11::path&)",
	"_SYSTEMD_SLICE" : "system-dropbear.slice",
	"CODE_LINE" : "174",
	"__REALTIME_TIMESTAMP" : "1686583867350640",
	"PRIORITY" : "3",
	"_SYSTEMD_UNIT" : "dropbear@1-9.3.29.238:22-9.3.84.138:45432.service",
	"_PID" : "16209",
	"_BOOT_ID" : "b372b9a5989e46bb8e62b33310e181ea",
	"_SOURCE_REALTIME_TIMESTAMP" : "1686583867350580",
	"_TRANSPORT" : "journal",
	"_HOSTNAME" : "openbmc",
	"SYSLOG_IDENTIFIER" : "phosphor-dump-manager",
	"MESSAGE" : "Invalid Dump file name, \
FILENAME: BMCDUMP.XXXXXXX.0000006.20230612153010",
	"CODE_FILE" : \
"/usr/src/debug/phosphor-debug-collector/1.0+gitAUTOINC+a17f1c92ce-r1\
/dump_manager_bmc.cpp",
	"_UID" : "0",
	"_CMDLINE" : "/tmp/phosphor-dump-manager",
	"_RUNTIME_SCOPE" : "system",
	"FILENAME" : "BMCDUMP.XXXXXXXX.0000006.20230612153010",
	"_SYSTEMD_INVOCATION_ID" : "64a11629aade4c96ab62154cbc4be8b7",
	"__MONOTONIC_TIMESTAMP" : "11817441835",
	"_SYSTEMD_CGROUP" : "/system.slice/system-dropbear.slice/\
dropbear@1-9.3.29.238:22-9.3.84.138:45432.service",
	"_COMM" : "phosphor-dump-m",
	"_GID" : "0"
}

Change-Id: I3a52b812b059b64d945493de2e2cc68a43f6d72a
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/dump-extensions/openpower-dumps/dump_manager_resource.cpp b/dump-extensions/openpower-dumps/dump_manager_resource.cpp
index 93ce98c..9c39b0a 100644
--- a/dump-extensions/openpower-dumps/dump_manager_resource.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_resource.cpp
@@ -7,10 +7,9 @@
 #include "resource_dump_entry.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
-#include <fmt/core.h>
-
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 namespace openpower
 {
@@ -45,11 +44,9 @@
         if ((resEntry->sourceDumpId() == dumpId) &&
             (resEntry->status() == phosphor::dump::OperationStatus::Completed))
         {
-            log<level::INFO>(
-                fmt::format("Resource dump entry with source dump id({}) is "
-                            "already present with entry id({})",
-                            dumpId, resEntry->getDumpId())
-                    .c_str());
+            lg2::info("Resource dump entry with source dump id: {DUMP_ID} "
+                      "is already present with entry id: {ENTRY_ID}",
+                      "DUMP_ID", dumpId, "ENTRY_ID", resEntry->getDumpId());
             return;
         }
 
@@ -66,11 +63,10 @@
     }
     if (upEntry != NULL)
     {
-        log<level::INFO>(
-            fmt::format("Resource Dump Notify: Updating dumpId({}) "
-                        "with source Id({}) Size({})",
-                        upEntry->getDumpId(), dumpId, size)
-                .c_str());
+        lg2::info("Resource Dump Notify: Updating dumpId: {DUMP_ID} with "
+                  "source Id: {SOURCE_ID} Size: {SIZE}",
+                  "DUMP_ID", upEntry->getDumpId(), "SOURCE_ID", dumpId, "SIZE",
+                  size);
         upEntry->update(timeStamp, size, dumpId);
         return;
     }
@@ -85,10 +81,10 @@
 
     try
     {
-        log<level::INFO>(fmt::format("Resouce Dump Notify: creating new dump "
-                                     "entry dumpId({}) Id({}) Size({})",
-                                     id, dumpId, size)
-                             .c_str());
+        lg2::info(
+            "Resouce Dump Notify: creating new dump entry dumpId: {DUMP_ID} "
+            "Id: {ID} Size: {SIZE}",
+            "DUMP_ID", id, "ID", dumpId, "SIZE", size);
         entries.insert(std::make_pair(
             id, std::make_unique<resource::Entry>(
                     bus, objPath.c_str(), id, timeStamp, size, dumpId,
@@ -98,12 +94,12 @@
     }
     catch (const std::invalid_argument& e)
     {
-        log<level::ERR>(fmt::format("Error in creating resource dump entry, "
-                                    "errormsg({}),OBJECTPATH({}),ID({}),"
-                                    "TIMESTAMP({}),SIZE({}),SOURCEID({})",
-                                    e.what(), objPath.c_str(), id, timeStamp,
-                                    size, dumpId)
-                            .c_str());
+        lg2::error(
+            "Error in creating resource dump entry, errormsg: {ERROR}, "
+            "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
+            "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}",
+            "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
+            timeStamp, "SIZE", size, "SOURCE_ID", dumpId);
         report<InternalFailure>();
         return;
     }
@@ -147,7 +143,7 @@
     {
         // Host will generate a default dump if no resource selector string
         // is provided. The default dump will be a non-disruptive system dump.
-        log<level::INFO>(
+        lg2::info(
             "VSP string is not provided, a non-disruptive system dump will be "
             "generated by the host");
     }
@@ -160,10 +156,8 @@
         catch (const std::bad_variant_access& e)
         {
             // Exception will be raised if the input is not string
-            log<level::ERR>(
-                fmt::format("An invalid  vsp string is passed errormsg({})",
-                            e.what())
-                    .c_str());
+            lg2::error("An invalid vsp string is passed, errormsg: {ERROR}",
+                       "ERROR", e);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("VSP_STRING"),
                                   Argument::ARGUMENT_VALUE("INVALID INPUT"));
         }
@@ -175,7 +169,7 @@
             convertCreateParametersToString(CreateParameters::Password));
     if (iter == params.end())
     {
-        log<level::INFO>("Password is not provided for resource dump");
+        lg2::info("Password is not provided for resource dump");
     }
     else
     {
@@ -186,10 +180,9 @@
         catch (const std::bad_variant_access& e)
         {
             // Exception will be raised if the input is not string
-            log<level::ERR>(
-                fmt::format("An invalid password string is passed errormsg({})",
-                            e.what())
-                    .c_str());
+            lg2::error(
+                "An invalid password string is passed, errormsg: {ERROR}",
+                "ERROR", e);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("PASSWORD"),
                                   Argument::ARGUMENT_VALUE("INVALID INPUT"));
         }
@@ -212,12 +205,11 @@
     }
     catch (const std::invalid_argument& e)
     {
-        log<level::ERR>(
-            fmt::format(
-                "Error in creating resource dump "
-                "entry,errormsg({}),OBJECTPATH({}), VSPSTRING({}), ID({})",
-                e.what(), objPath.c_str(), vspString, id)
-                .c_str());
+        lg2::error(
+            "Error in creating resource dump entry, errormsg: {ERROR}, "
+            "OBJECTPATH: {OBJECT_PATH}, VSPSTRING: {VSP_STRING}, ID: {ID}",
+            "ERROR", e, "OBJECT_PATH", objPath, "VSP_STRING", vspString, "ID",
+            id);
         elog<InternalFailure>();
         return std::string();
     }
diff --git a/dump-extensions/openpower-dumps/dump_manager_system.cpp b/dump-extensions/openpower-dumps/dump_manager_system.cpp
index 558b0e3..af8972a 100644
--- a/dump-extensions/openpower-dumps/dump_manager_system.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_system.cpp
@@ -7,10 +7,9 @@
 #include "system_dump_entry.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
-#include <fmt/core.h>
-
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 namespace openpower
 {
@@ -64,12 +63,12 @@
     }
     catch (const std::invalid_argument& e)
     {
-        log<level::ERR>(
-            fmt::format(
-                "Error in creating system dump entry, errormsg({}), "
-                "OBJECTPATH({}), ID({}), TIMESTAMP({}),SIZE({}), SOURCEID({})",
-                e.what(), objPath.c_str(), id, timeStamp, size, dumpId)
-                .c_str());
+        lg2::error(
+            "Error in creating system dump entry, errormsg: {ERROR}, "
+            "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
+            "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}",
+            "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
+            timeStamp, "SIZE", size, "SOURCE_ID", dumpId);
         report<InternalFailure>();
         return;
     }
@@ -87,7 +86,7 @@
 
     if (params.size() > CREATE_DUMP_MAX_PARAMS)
     {
-        log<level::WARNING>(
+        lg2::warning(
             "System dump accepts not more than 2 additional parameters");
     }
 
@@ -135,11 +134,9 @@
     }
     catch (const std::invalid_argument& e)
     {
-        log<level::ERR>(
-            fmt::format("Error in creating system dump entry, errormsg({}), "
-                        "OBJECTPATH({}), ID({})",
-                        e.what(), objPath.c_str(), id)
-                .c_str());
+        lg2::error("Error in creating system dump entry, errormsg: {ERROR}, "
+                   "OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
+                   "ERROR", e, "OBJECT_PATH", objPath, "ID", id);
         elog<InternalFailure>();
         return std::string();
     }
diff --git a/dump-extensions/openpower-dumps/resource_dump_entry.cpp b/dump-extensions/openpower-dumps/resource_dump_entry.cpp
index 3a98d9e..17125fe 100644
--- a/dump-extensions/openpower-dumps/resource_dump_entry.cpp
+++ b/dump-extensions/openpower-dumps/resource_dump_entry.cpp
@@ -4,9 +4,8 @@
 #include "host_transport_exts.hpp"
 #include "op_dump_consts.hpp"
 
-#include <fmt/core.h>
-
 #include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 namespace openpower
@@ -26,11 +25,9 @@
     using NotAllowed =
         sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
     using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
-    log<level::INFO>(
-        fmt::format(
-            "Resource dump offload request id({}) uri({}) source dumpid({})",
-            id, uri, sourceDumpId())
-            .c_str());
+    lg2::info("Resource dump offload request id: {ID} uri: {URI} "
+              "source dumpid: {SOURCE_DUMP_ID}",
+              "ID", id, "URI", uri, "SOURCE_DUMP_ID", sourceDumpId());
 
     if (!phosphor::dump::isHostRunning())
     {
@@ -49,19 +46,16 @@
 
     if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning()))
     {
-        log<level::ERR>(
-            fmt::format("Dump offload is in progress, cannot delete "
-                        "dump, id({}) srcdumpid({})",
-                        dumpId, srcDumpID)
-                .c_str());
+        lg2::error("Dump offload is in progress, cannot delete dump, "
+                   "id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
+                   "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
         elog<sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed>(
             xyz::openbmc_project::Common::NotAllowed::REASON(
                 "Dump offload is in progress"));
     }
 
-    log<level::INFO>(fmt::format("Resource dump delete id({}) srcdumpid({})",
-                                 dumpId, srcDumpID)
-                         .c_str());
+    lg2::info("Resource dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
+              "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
 
     // Remove resource dump when host is up by using source dump id
 
@@ -75,10 +69,9 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>(fmt::format("Error deleting dump from host id({}) "
-                                        "host id({}) error({})",
-                                        dumpId, srcDumpID, e.what())
-                                .c_str());
+            lg2::error("Error deleting dump from host id: {DUMP_ID} "
+                       "host id: {SRC_DUMP_ID} error: {ERROR}",
+                       "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID, "ERROR", e);
             elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
         }
     }
diff --git a/dump-extensions/openpower-dumps/system_dump_entry.cpp b/dump-extensions/openpower-dumps/system_dump_entry.cpp
index 39b161d..3d0fb51 100644
--- a/dump-extensions/openpower-dumps/system_dump_entry.cpp
+++ b/dump-extensions/openpower-dumps/system_dump_entry.cpp
@@ -4,9 +4,8 @@
 #include "host_transport_exts.hpp"
 #include "op_dump_consts.hpp"
 
-#include <fmt/core.h>
-
 #include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 namespace openpower
@@ -23,11 +22,9 @@
 
 void Entry::initiateOffload(std::string uri)
 {
-    log<level::INFO>(
-        fmt::format(
-            "System dump offload request id({}) uri({}) source dumpid()", id,
-            uri, sourceDumpId())
-            .c_str());
+    lg2::info("System dump offload request id: {ID} uri: {URI} "
+              "source dumpid: {SOURCE_DUMP_ID}",
+              "ID", id, "URI", uri, "SOURCE_DUMP_ID", sourceDumpId());
     phosphor::dump::Entry::initiateOffload(uri);
     phosphor::dump::host::requestOffload(sourceDumpId());
 }
@@ -39,18 +36,16 @@
 
     if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning()))
     {
-        log<level::ERR>(
-            fmt::format("Dump offload is in progress id({}) srcdumpid({})",
-                        dumpId, srcDumpID)
-                .c_str());
+        lg2::error("Dump offload is in progress id: {DUMP_ID} "
+                   "srcdumpid: {SRC_DUMP_ID}",
+                   "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
         elog<sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed>(
             xyz::openbmc_project::Common::NotAllowed::REASON(
                 "Dump offload is in progress"));
     }
 
-    log<level::INFO>(fmt::format("System dump delete id({}) srcdumpid({})",
-                                 dumpId, srcDumpID)
-                         .c_str());
+    lg2::info("System dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
+              "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
 
     // Remove host system dump when host is up by using source dump id
     // which is present in system dump entry dbus object as a property.
@@ -63,10 +58,9 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>(fmt::format("Error deleting dump from host id({}) "
-                                        "host id({}) error({})",
-                                        dumpId, srcDumpID, e.what())
-                                .c_str());
+            lg2::error("Error deleting dump from host id: {DUMP_ID} "
+                       "host id: {SRC_DUMP_ID} error: {ERROR}",
+                       "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID, "ERROR", e);
             elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
         }
     }