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_manager_bmc.cpp b/dump_manager_bmc.cpp
index 3ef3699..8161f41 100644
--- a/dump_manager_bmc.cpp
+++ b/dump_manager_bmc.cpp
@@ -7,12 +7,12 @@
 #include "xyz/openbmc_project/Common/error.hpp"
 #include "xyz/openbmc_project/Dump/Create/error.hpp"
 
-#include <fmt/core.h>
 #include <sys/inotify.h>
 #include <unistd.h>
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdeventplus/exception.hpp>
 #include <sdeventplus/source/base.hpp>
 
@@ -47,8 +47,7 @@
 {
     if (params.size() > CREATE_DUMP_MAX_PARAMS)
     {
-        log<level::WARNING>(
-            "BMC dump accepts not more than 2 additional parameters");
+        lg2::warning("BMC dump accepts not more than 2 additional parameters");
     }
 
     if (Manager::fUserDumpInProgress == true)
@@ -84,10 +83,9 @@
     }
     catch (const std::invalid_argument& e)
     {
-        log<level::ERR>(fmt::format("Error in creating dump entry, "
-                                    "errormsg({}), OBJECTPATH({}), ID({})",
-                                    e.what(), objPath.c_str(), id)
-                            .c_str());
+        lg2::error("Error in creating dump entry, errormsg: {ERROR}, "
+                   "OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
+                   "ERROR", e, "OBJECT_PATH", objPath, "ID", id);
         elog<InternalFailure>();
     }
 
@@ -118,10 +116,9 @@
 
         // dreport script execution is failed.
         auto error = errno;
-        log<level::ERR>(fmt::format("Error occurred during dreport "
-                                    "function execution, errno({})",
-                                    error)
-                            .c_str());
+        lg2::error("Error occurred during dreport function execution, "
+                   "errno: {ERRNO}",
+                   "ERRNO", error);
         elog<InternalFailure>();
     }
     else if (pid > 0)
@@ -129,8 +126,7 @@
         Child::Callback callback = [this, type, pid](Child&, const siginfo_t*) {
             if (type == Type::UserRequested)
             {
-                log<level::INFO>(
-                    "User initiated dump completed, resetting flag");
+                lg2::info("User initiated dump completed, resetting flag");
                 Manager::fUserDumpInProgress = false;
             }
             this->childPtrMap.erase(pid);
@@ -145,21 +141,18 @@
         catch (const sdeventplus::SdEventError& ex)
         {
             // Failed to add to event loop
-            log<level::ERR>(
-                fmt::format(
-                    "Error occurred during the sdeventplus::source::Child "
-                    "creation ex({})",
-                    ex.what())
-                    .c_str());
+            lg2::error(
+                "Error occurred during the sdeventplus::source::Child creation "
+                "ex: {ERROR}",
+                "ERROR", ex);
             elog<InternalFailure>();
         }
     }
     else
     {
         auto error = errno;
-        log<level::ERR>(
-            fmt::format("Error occurred during fork, errno({})", error)
-                .c_str());
+        lg2::error("Error occurred during fork, errno: {ERRNO}", "ERRNO",
+                   error);
         elog<InternalFailure>();
     }
     return ++lastEntryId;
@@ -177,9 +170,8 @@
 
     if (!((std::regex_search(name, match, file_regex)) && (match.size() > 0)))
     {
-        log<level::ERR>(fmt::format("Invalid Dump file name, FILENAME({})",
-                                    file.filename().c_str())
-                            .c_str());
+        lg2::error("Invalid Dump file name, FILENAME: {FILENAME}", "FILENAME",
+                   file);
         return;
     }
 
@@ -213,14 +205,13 @@
     }
     catch (const std::invalid_argument& e)
     {
-        log<level::ERR>(
-            fmt::format("Error in creating dump entry, errormsg({}), "
-                        "OBJECTPATH({}), "
-                        "ID({}), TIMESTAMP({}), SIZE({}), FILENAME({})",
-                        e.what(), objPath.c_str(), id, timestamp,
-                        std::filesystem::file_size(file),
-                        file.filename().c_str())
-                .c_str());
+        lg2::error(
+            "Error in creating dump entry, errormsg: {ERROR}, "
+            "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
+            "SIZE: {SIZE}, FILENAME: {FILENAME}",
+            "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
+            timestamp, "SIZE", std::filesystem::file_size(file), "FILENAME",
+            file);
         return;
     }
 }