Port phosphor::logging to lg2

Added patch which ports all the phosphor::log to lg2

Tested:
1) No crash is seen when smbios-mdr is loaded


Change-Id: If6d1f24eb34be7370382c18b76eff7897e305226
Signed-off-by: Prithvi Pai <ppai@nvidia.com>
diff --git a/src/dimm.cpp b/src/dimm.cpp
index d0c8b91..ce63f4f 100644
--- a/src/dimm.cpp
+++ b/src/dimm.cpp
@@ -20,6 +20,7 @@
 
 #include <boost/algorithm/string.hpp>
 #include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <fstream>
 #include <iostream>
@@ -126,8 +127,7 @@
         dataIn = getSMBIOSTypePtr(dataIn, physicalMemoryArrayType);
         if (dataIn == nullptr)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Failed to get SMBIOS table type-16 data.");
+            lg2::error("Failed to get SMBIOS table type-16 data.");
             return;
         }
 
@@ -149,9 +149,9 @@
 
         dataIn = smbiosNextPtr(dataIn);
     }
-    phosphor::logging::log<phosphor::logging::level::ERR>(
-        "Failed find the corresponding SMBIOS table type-16 data for dimm:",
-        phosphor::logging::entry("DIMM:%d", dimmNum));
+    lg2::error(
+        "Failed find the corresponding SMBIOS table type-16 data for dimm: {DIMM}",
+        "DIMM", dimmNum);
 }
 
 EccType Dimm::ecc(EccType value)
@@ -246,9 +246,8 @@
             memoryController(0);
             slot(0);
             channel(0);
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Failed find the corresponding table for dimm ",
-                phosphor::logging::entry("DIMM:%s", deviceLocator.c_str()));
+            lg2::error("Failed find the corresponding table for dimm {DIMM}",
+                       "DIMM", deviceLocator.c_str());
         }
     }
     else
@@ -265,9 +264,8 @@
             }
             catch (const sdbusplus::exception_t& ex)
             {
-                phosphor::logging::log<phosphor::logging::level::ERR>(
-                    "std::stoi operation failed ",
-                    phosphor::logging::entry("ERROR=%s", ex.what()));
+                lg2::error("std::stoi operation failed {ERROR}", "ERROR",
+                           ex.what());
             }
         }
     }
@@ -473,17 +471,15 @@
 
     if (!memoryLocationFile.is_open())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "config JSON file not found, FILENAME ",
-            phosphor::logging::entry("%s", filename));
+        lg2::error("config JSON file not found, FILENAME {FILENAME}",
+                   "FILENAME", filename);
         return {};
     }
 
     auto data = Json::parse(memoryLocationFile, nullptr, false);
     if (data.is_discarded())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "config readings JSON parser failure");
+        lg2::error("config readings JSON parser failure");
         return {};
     }
 
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 8395c94..357fb02 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -38,7 +38,7 @@
     std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
     if (!smbiosFile.good())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
+        lg2::error(
             "Read data from flash error - Open MDRV2 table file failure");
         throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
             InvalidParameter();
@@ -126,8 +126,7 @@
     }
     else
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "smbios is not ready for update");
+        lg2::error("smbios is not ready for update");
         throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
             UpdateInProgress();
     }
@@ -206,20 +205,18 @@
 {
     if (mdrHdr == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Read data from flash error - Invalid mdr header");
+        lg2::error("Read data from flash error - Invalid mdr header");
         return false;
     }
     if (data == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Read data from flash error - Invalid data point");
+        lg2::error("Read data from flash error - Invalid data point");
         return false;
     }
     std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
     if (!smbiosFile.good())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
+        lg2::error(
             "Read data from flash error - Open MDRV2 table file failure");
         return false;
     }
@@ -229,15 +226,13 @@
     smbiosFile.seekg(0, std::ios_base::beg);
     if (fileLength < sizeof(MDRSMBIOSHeader))
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "MDR V2 file size is smaller than mdr header");
+        lg2::error("MDR V2 file size is smaller than mdr header");
         return false;
     }
     smbiosFile.read(reinterpret_cast<char*>(mdrHdr), sizeof(MDRSMBIOSHeader));
     if (mdrHdr->dataSize > smbiosTableStorageSize)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Data size out of limitation");
+        lg2::error("Data size out of limitation");
         smbiosFile.close();
         return false;
     }
@@ -261,16 +256,14 @@
     bool terminate = false;
     if ((dirIndex >= maxDirEntries) || (returnedEntries < 1))
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Send Dir info failed - input parameter invalid");
+        lg2::error("Send Dir info failed - input parameter invalid");
         throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
             InvalidParameter();
     }
     if ((static_cast<size_t>(returnedEntries) * sizeof(DataIdStruct)) !=
         dirEntry.size())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Directory size invalid");
+        lg2::error("Directory size invalid");
         throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
             InvalidParameter();
     }
@@ -346,8 +339,7 @@
 {
     if (dataInfo.size() != sizeof(DataIdStruct))
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Length of dataInfo invalid");
+        lg2::error("Length of dataInfo invalid");
         throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
             InvalidId();
     }
@@ -379,7 +371,7 @@
     std::ifstream smbiosFile(smbiosFilePath, std::ios_base::binary);
     if (!smbiosFile.good())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
+        lg2::error(
             "Read data from flash error - Open MDRV2 table file failure");
         value = 0;
     }
@@ -446,16 +438,14 @@
         lg2::error(
             "Exception while trying to find Inventory anchor object for SMBIOS content {I}: {E}",
             "I", smbiosInventoryPath, "E", e.what());
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Failed to query system motherboard",
-            phosphor::logging::entry("ERROR=%s", e.what()));
+        lg2::error("Failed to query system motherboard: {ERROR}", "ERROR",
+                   e.what());
     }
 
     if (motherboardPath.empty())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Failed to get system motherboard dbus path. Setting up a "
-            "match rule");
+        lg2::error(
+            "Failed to get system motherboard dbus path. Setting up a match rule");
 
         if (motherboardConfigMatch)
         {
@@ -525,8 +515,7 @@
     std::optional<size_t> num = getTotalCpuSlot();
     if (!num)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "get cpu total slot failed");
+        lg2::error("get cpu total slot failed");
         return;
     }
 
@@ -558,8 +547,7 @@
     num = getTotalDimmSlot();
     if (!num)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "get dimm total slot failed");
+        lg2::error("get dimm total slot failed");
         return;
     }
 
@@ -591,8 +579,7 @@
     num = getTotalPcieSlot();
     if (!num)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "get pcie total slot failed");
+        lg2::error("get pcie total slot failed");
         return;
     }
 
@@ -624,7 +611,7 @@
     num = getTotalTpm();
     if (!num)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>("get tpm failed");
+        lg2::error("get tpm failed");
         return;
     }
     // In case the new size is smaller than old, trim the vector
@@ -657,8 +644,7 @@
     num = getTotalFirmwareInventory();
     if (!num)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "get firmware inventory failed");
+        lg2::error("get firmware inventory failed");
         existingVersionPaths.clear();
         return;
     }
@@ -697,8 +683,7 @@
 
     if (dataIn == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "get cpu total slot failed - no storage data");
+        lg2::error("get cpu total slot failed - no storage data");
         return std::nullopt;
     }
 
@@ -731,8 +716,7 @@
 
     if (dataIn == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Fail to get dimm total slot - no storage data");
+        lg2::error("Fail to get dimm total slot - no storage data");
         return std::nullopt;
     }
 
@@ -765,8 +749,7 @@
 
     if (dataIn == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Fail to get total system slot - no storage data");
+        lg2::error("Fail to get total system slot - no storage data");
         return std::nullopt;
     }
 
@@ -806,8 +789,7 @@
 
     if (dataIn == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Fail to get tpm total slot - no storage data");
+        lg2::error("Fail to get tpm total slot - no storage data");
         return std::nullopt;
     }
 
@@ -840,8 +822,7 @@
 
     if (dataIn == nullptr)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Fail to get firmware inventory - no storage data");
+        lg2::error("Fail to get firmware inventory - no storage data");
         return std::nullopt;
     }
 
@@ -879,14 +860,12 @@
     bool smbios21Found = it != std::end(buffer);
     if (!smbios21Found)
     {
-        phosphor::logging::log<phosphor::logging::level::INFO>(
-            "SMBIOS 2.1 Anchor String not found. Looking for SMBIOS 3.0");
+        lg2::info("SMBIOS 2.1 Anchor String not found. Looking for SMBIOS 3.0");
         it = std::search(std::begin(buffer), std::end(buffer),
                          std::begin(anchorString30), std::end(anchorString30));
         if (it == std::end(buffer))
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "SMBIOS 2.1 and 3.0 Anchor Strings not found");
+            lg2::error("SMBIOS 2.1 and 3.0 Anchor Strings not found");
             return false;
         }
     }
@@ -900,8 +879,7 @@
     {
         if (length < sizeof(EntryPointStructure21))
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Invalid entry point structure for SMBIOS 2.1");
+            lg2::error("Invalid entry point structure for SMBIOS 2.1");
             return false;
         }
 
@@ -914,8 +892,7 @@
     {
         if (length < sizeof(EntryPointStructure30))
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Invalid entry point structure for SMBIOS 3.0");
+            lg2::error("Invalid entry point structure for SMBIOS 3.0");
             return false;
         }
 
@@ -935,6 +912,7 @@
         });
     if (itr == std::end(supportedSMBIOSVersions))
     {
+        lg2::error("Unsupported SMBIOS table version");
         return false;
     }
     return true;
@@ -947,15 +925,13 @@
                                     smbiosDir.dir[smbiosDirIndex].dataStorage);
     if (!status)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "agent data sync failed - read data from flash failed");
+        lg2::error("agent data sync failed - read data from flash failed");
         return false;
     }
 
     if (!checkSMBIOSVersion(smbiosDir.dir[smbiosDirIndex].dataStorage))
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Unsupported SMBIOS table version");
+        lg2::error("Unsupported SMBIOS table version");
         return false;
     }
 
@@ -990,8 +966,7 @@
     timer.async_wait([this](boost::system::error_code ec) {
         if (ec)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Timer Error!");
+            lg2::error("Timer Error!");
             return;
         }
         agentSynchronizeData();
diff --git a/src/smbios-ipmi-blobs/handler.cpp b/src/smbios-ipmi-blobs/handler.cpp
index b30a99a..ff68353 100644
--- a/src/smbios-ipmi-blobs/handler.cpp
+++ b/src/smbios-ipmi-blobs/handler.cpp
@@ -7,7 +7,7 @@
 #include <unistd.h>
 
 #include <ipmid/api.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/exception.hpp>
 #include <sdbusplus/message.hpp>
@@ -45,19 +45,15 @@
     }
     catch (const sdbusplus::exception_t& e)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Error Sync data with service",
-            phosphor::logging::entry("ERROR=%s", e.what()),
-            phosphor::logging::entry("SERVICE=%s", mdrV2Service),
-            phosphor::logging::entry("PATH=%s",
-                                     phosphor::smbios::defaultObjectPath));
+        lg2::error("Error Sync data with service: {E} SERVICE={S} PATH={P}",
+                   "E", e.what(), "S", mdrV2Service, "P",
+                   phosphor::smbios::defaultObjectPath);
         return false;
     }
 
     if (!status)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Sync data with service failure");
+        lg2::error("Sync data with service failure");
         return false;
     }
 
@@ -130,8 +126,7 @@
 
     if (!(blobPtr->state & blobs::StateFlags::open_write))
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "No open blob to write");
+        lg2::error("No open blob to write");
         return false;
     }
 
@@ -170,8 +165,7 @@
 {
     if (!data.empty())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Unexpected data provided to commit call");
+        lg2::error("Unexpected data provided to commit call");
         return false;
     }
 
@@ -205,8 +199,7 @@
         int flag = mkdir(defaultDir.c_str(), S_IRWXU);
         if (flag != 0)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "create folder failed for writing smbios file");
+            lg2::error("create folder failed for writing smbios file");
             blobPtr->state |= blobs::StateFlags::commit_error;
             return false;
         }
@@ -216,7 +209,7 @@
                              std::ios_base::binary | std::ios_base::trunc);
     if (!smbiosFile.good())
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
+        lg2::error(
             "Write data from flash error - Open SMBIOS table file failure");
         blobPtr->state |= blobs::StateFlags::commit_error;
         return false;
@@ -234,9 +227,8 @@
     }
     catch (const std::ofstream::failure& e)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Write data from flash error - write data error",
-            phosphor::logging::entry("ERROR=%s", e.what()));
+        lg2::error("Write data from flash error - write data error: {E}", "E",
+                   e.what());
         blobPtr->state |= blobs::StateFlags::commit_error;
         return false;
     }
diff --git a/src/smbios-ipmi-blobs/test/meson.build b/src/smbios-ipmi-blobs/test/meson.build
index e4e2828..0182b88 100644
--- a/src/smbios-ipmi-blobs/test/meson.build
+++ b/src/smbios-ipmi-blobs/test/meson.build
@@ -16,7 +16,12 @@
             t + '.cpp',
             '../handler.cpp',
             include_directories: ['../', root_inc],
-            dependencies: [smbiosstore_common_deps, gtest, gmock],
+            dependencies: [
+                smbiosstore_common_deps,
+                gtest,
+                gmock,
+                phosphor_logging_dep,
+            ],
         ),
         protocol: 'gtest',
     )
diff --git a/src/system.cpp b/src/system.cpp
index 7a37263..b3e58bd 100644
--- a/src/system.cpp
+++ b/src/system.cpp
@@ -136,13 +136,12 @@
             std::ofstream smbiosFile(smbiosFilePath, std::ios_base::trunc);
             if (!smbiosFile.good())
             {
-                phosphor::logging::log<phosphor::logging::level::ERR>(
-                    "Open MDRV2 table file failure");
+                lg2::error("Open MDRV2 table file failure");
                 return result;
             }
             smbiosFile.clear();
             smbiosFile.close();
-            phosphor::logging::log<phosphor::logging::level::ERR>(
+            lg2::error(
                 "Find non-print char, delete the broken MDRV2 table file!");
             return sdbusplus::server::xyz::openbmc_project::inventory::
                 decorator::Revision::version(result);