remove phosphor-logging dependency

This commit removes pldm's dependency on phosphor-logging
and instead uses stdout and stdcerr for logging purpose.This is to
break the build time circular dependency between pldm and
phosphor-logging.

Change-Id: I8cffa3c99eb34efad5f186b3452a86ebadec2074
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/oem/ibm/libpldmresponder/file_io.cpp b/oem/ibm/libpldmresponder/file_io.cpp
index be0c95b..6f65b97 100644
--- a/oem/ibm/libpldmresponder/file_io.cpp
+++ b/oem/ibm/libpldmresponder/file_io.cpp
@@ -15,23 +15,20 @@
 
 #include <cstring>
 #include <fstream>
+#include <iostream>
 #include <memory>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
 
 #include "libpldm/base.h"
 
 namespace pldm
 {
 
-using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
 
 namespace responder
 {
 
 namespace fs = std::filesystem;
-using namespace phosphor::logging;
 
 namespace dma
 {
@@ -74,7 +71,7 @@
     if (fd < 0)
     {
         rc = -errno;
-        log<level::ERR>("Failed to open the XDMA device", entry("RC=%d", rc));
+        std::cerr << "Failed to open the XDMA device, RC=" << rc << "\n";
         return rc;
     }
 
@@ -86,7 +83,7 @@
     if (MAP_FAILED == vgaMem)
     {
         rc = -errno;
-        log<level::ERR>("Failed to mmap the XDMA device", entry("RC=%d", rc));
+        std::cerr << "Failed to mmap the XDMA device, RC=" << rc << "\n";
         return rc;
     }
 
@@ -108,10 +105,9 @@
 
         if (static_cast<uint32_t>(stream.gcount()) != length)
         {
-            log<level::ERR>("mismatch between number of characters to read and "
-                            "the length read",
-                            entry("LENGTH=%d", length),
-                            entry("COUNT=%d", stream.gcount()));
+            std::cerr << "mismatch between number of characters to read and "
+                      << "the length read, LENGTH=" << length
+                      << " COUNT=" << stream.gcount() << "\n";
             return -1;
         }
     }
@@ -125,10 +121,9 @@
     if (rc < 0)
     {
         rc = -errno;
-        log<level::ERR>("Failed to execute the DMA operation",
-                        entry("RC=%d", rc), entry("UPSTREAM=%d", upstream),
-                        entry("ADDRESS=%lld", address),
-                        entry("LENGTH=%d", length));
+        std::cerr << "Failed to execute the DMA operation, RC=" << rc
+                  << " UPSTREAM=" << upstream << " ADDRESS=" << address
+                  << " LENGTH=" << length << "\n";
         return rc;
     }
 
@@ -185,8 +180,8 @@
     }
     catch (std::exception& e)
     {
-        log<level::ERR>("File handle does not exist in the file table",
-                        entry("HANDLE=%d", fileHandle));
+        std::cerr << "File handle does not exist in the file table, HANDLE="
+                  << fileHandle << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -195,7 +190,7 @@
 
     if (!fs::exists(value.fsPath))
     {
-        log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle));
+        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -205,8 +200,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
-                        entry("FILE_SIZE=%d", fileSize));
+        std::cerr << "Offset exceeds file size, OFFSET=" << offset
+                  << " FILE_SIZE=" << fileSize << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
@@ -220,8 +215,8 @@
 
     if (length % dma::minSize)
     {
-        log<level::ERR>("Read length is not a multiple of DMA minSize",
-                        entry("LENGTH=%d", length));
+        std::cerr << "Read length is not a multiple of DMA minSize, LENGTH="
+                  << length << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_INVALID_READ_LENGTH, 0, responsePtr);
@@ -259,8 +254,8 @@
 
     if (length % dma::minSize)
     {
-        log<level::ERR>("Write length is not a multiple of DMA minSize",
-                        entry("LENGTH=%d", length));
+        std::cerr << "Write length is not a multiple of DMA minSize, LENGTH="
+                  << length << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_INVALID_WRITE_LENGTH, 0, responsePtr);
@@ -277,8 +272,8 @@
     }
     catch (std::exception& e)
     {
-        log<level::ERR>("File handle does not exist in the file table",
-                        entry("HANDLE=%d", fileHandle));
+        std::cerr << "File handle does not exist in the file table, HANDLE="
+                  << fileHandle << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -287,7 +282,7 @@
 
     if (!fs::exists(value.fsPath))
     {
-        log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle));
+        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -297,8 +292,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
-                        entry("FILE_SIZE=%d", fileSize));
+        std::cerr << "Offset exceeds file size, OFFSET=" << offset
+                  << " FILE_SIZE=" << fileSize << "\n";
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
@@ -402,8 +397,8 @@
     }
     catch (std::exception& e)
     {
-        log<level::ERR>("File handle does not exist in the file table",
-                        entry("HANDLE=%d", fileHandle));
+        std::cerr << "File handle does not exist in the file table, HANDLE="
+                  << fileHandle << "\n";
         encode_read_file_resp(request->hdr.instance_id,
                               PLDM_INVALID_FILE_HANDLE, length, responsePtr);
         return response;
@@ -411,7 +406,7 @@
 
     if (!fs::exists(value.fsPath))
     {
-        log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle));
+        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
         encode_read_file_resp(request->hdr.instance_id,
                               PLDM_INVALID_FILE_HANDLE, length, responsePtr);
         return response;
@@ -420,8 +415,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
-                        entry("FILE_SIZE=%d", fileSize));
+        std::cerr << "Offset exceeds file size, OFFSET=" << offset
+                  << " FILE_SIZE=" << fileSize << "\n";
         encode_read_file_resp(request->hdr.instance_id, PLDM_DATA_OUT_OF_RANGE,
                               length, responsePtr);
         return response;
@@ -483,8 +478,8 @@
     }
     catch (std::exception& e)
     {
-        log<level::ERR>("File handle does not exist in the file table",
-                        entry("HANDLE=%d", fileHandle));
+        std::cerr << "File handle does not exist in the file table, HANDLE="
+                  << fileHandle << "\n";
         encode_write_file_resp(request->hdr.instance_id,
                                PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
         return response;
@@ -492,7 +487,7 @@
 
     if (!fs::exists(value.fsPath))
     {
-        log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle));
+        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
         encode_write_file_resp(request->hdr.instance_id,
                                PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
         return response;
@@ -501,8 +496,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
-                        entry("FILE_SIZE=%d", fileSize));
+        std::cerr << "Offset exceeds file size, OFFSET=" << offset
+                  << " FILE_SIZE=" << fileSize << "\n";
         encode_write_file_resp(request->hdr.instance_id, PLDM_DATA_OUT_OF_RANGE,
                                0, responsePtr);
         return response;
@@ -553,8 +548,8 @@
     }
     if (length % dma::minSize)
     {
-        log<level::ERR>("Length is not a multiple of DMA minSize",
-                        entry("LENGTH=%d", length));
+        std::cerr << "Length is not a multiple of DMA minSize, LENGTH="
+                  << length << "\n";
         encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
                                            PLDM_INVALID_WRITE_LENGTH, 0,
                                            responsePtr);
@@ -568,7 +563,7 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("unknown file type ", entry("TYPE=%d", fileType));
+        std::cerr << "unknown file type, TYPE=" << fileType << "\n";
         encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
                                            PLDM_INVALID_FILE_TYPE, 0,
                                            responsePtr);
@@ -630,7 +625,7 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("unknown file type", entry("TYPE=%d", fileType));
+        std::cerr << "unknown file type, TYPE=" << fileType << "\n";
         encode_rw_file_by_type_resp(request->hdr.instance_id,
                                     PLDM_READ_FILE_BY_TYPE,
                                     PLDM_INVALID_FILE_TYPE, 0, responsePtr);
diff --git a/oem/ibm/libpldmresponder/file_io_by_type.cpp b/oem/ibm/libpldmresponder/file_io_by_type.cpp
index efe8e37..7a95a6d 100644
--- a/oem/ibm/libpldmresponder/file_io_by_type.cpp
+++ b/oem/ibm/libpldmresponder/file_io_by_type.cpp
@@ -13,8 +13,7 @@
 #include <exception>
 #include <filesystem>
 #include <fstream>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <iostream>
 #include <vector>
 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
 
@@ -26,7 +25,6 @@
 namespace responder
 {
 
-using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
 
 int FileHandler::transferFileData(const fs::path& path, bool upstream,
@@ -37,17 +35,15 @@
     {
         if (!fs::exists(path))
         {
-            log<level::ERR>("File does not exist",
-                            entry("PATH=%s", path.c_str()));
+            std::cerr << "File does not exist. PATH=" << path.c_str() << "\n";
             return PLDM_INVALID_FILE_HANDLE;
         }
 
         size_t fileSize = fs::file_size(path);
         if (offset >= fileSize)
         {
-            log<level::ERR>("Offset exceeds file size",
-                            entry("OFFSET=%d", offset),
-                            entry("FILE_SIZE=%d", fileSize));
+            std::cerr << "Offset exceeds file size, OFFSET=" << offset
+                      << " FILE_SIZE=" << fileSize << "\n";
             return PLDM_DATA_OUT_OF_RANGE;
         }
         if (offset + length > fileSize)
@@ -97,7 +93,7 @@
         }
         default:
         {
-            elog<InternalFailure>();
+            throw InternalFailure();
             break;
         }
     }
@@ -109,16 +105,16 @@
 {
     if (!fs::exists(filePath))
     {
-        log<level::ERR>("File does not exist", entry("HANDLE=%d", fileHandle),
-                        entry("PATH=%s", filePath.c_str()));
+        std::cerr << "File does not exist, HANDLE=" << fileHandle
+                  << " PATH=" << filePath.c_str() << "\n";
         return PLDM_INVALID_FILE_HANDLE;
     }
 
     size_t fileSize = fs::file_size(filePath);
     if (offset >= fileSize)
     {
-        log<level::ERR>("Offset exceeds file size", entry("OFFSET=%d", offset),
-                        entry("FILE_SIZE=%d", fileSize));
+        std::cerr << "Offset exceeds file size, OFFSET=" << offset
+                  << " FILE_SIZE=" << fileSize << "\n";
         return PLDM_DATA_OUT_OF_RANGE;
     }
 
@@ -138,7 +134,7 @@
         stream.read(filePos, length);
         return PLDM_SUCCESS;
     }
-    log<level::ERR>("Unable to read file", entry("FILE=%s", filePath.c_str()));
+    std::cerr << "Unable to read file, FILE=" << filePath.c_str() << "\n";
     return PLDM_ERROR;
 }
 
diff --git a/oem/ibm/libpldmresponder/file_io_type_pel.cpp b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
index a5fa49a..c919c27 100644
--- a/oem/ibm/libpldmresponder/file_io_type_pel.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
@@ -11,6 +11,7 @@
 
 #include <exception>
 #include <filesystem>
+#include <iostream>
 #include <sdbusplus/server.hpp>
 #include <vector>
 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
@@ -23,8 +24,6 @@
 namespace responder
 {
 
-using namespace phosphor::logging;
-
 int PelHandler::readIntoMemory(uint32_t /*offset*/, uint32_t& /*length*/,
                                uint64_t /*address*/)
 {
@@ -44,8 +43,8 @@
     int fd = mkstemp(tmpFile);
     if (fd == -1)
     {
-        log<level::ERR>("failed to create a temporary pel",
-                        entry("ERROR=%d", errno));
+        std::cerr << "failed to create a temporary pel, ERROR=" << errno
+                  << "\n";
         return PLDM_ERROR;
     }
     close(fd);
@@ -86,8 +85,8 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("failed to make a d-bus call to PEL daemon",
-                        entry("ERROR=%s", e.what()));
+        std::cerr << "failed to make a d-bus call to PEL daemon, ERROR="
+                  << e.what() << "\n";
         return PLDM_ERROR;
     }
 
diff --git a/oem/ibm/libpldmresponder/file_table.cpp b/oem/ibm/libpldmresponder/file_table.cpp
index 9264f21..4b3198c 100644
--- a/oem/ibm/libpldmresponder/file_table.cpp
+++ b/oem/ibm/libpldmresponder/file_table.cpp
@@ -2,7 +2,7 @@
 
 #include <boost/crc.hpp>
 #include <fstream>
-#include <phosphor-logging/log.hpp>
+#include <iostream>
 
 namespace pldm
 {
@@ -10,22 +10,21 @@
 namespace filetable
 {
 
-using namespace phosphor::logging;
-
 FileTable::FileTable(const std::string& fileTableConfigPath)
 {
     std::ifstream jsonFile(fileTableConfigPath);
     if (!jsonFile.is_open())
     {
-        log<level::ERR>("File table config file does not exist",
-                        entry("FILE=%s", fileTableConfigPath.c_str()));
+        std::cerr << "File table config file does not exist, FILE="
+                  << fileTableConfigPath.c_str() << "\n";
         return;
     }
 
     auto data = Json::parse(jsonFile, nullptr, false);
     if (data.is_discarded())
     {
-        log<level::ERR>("Parsing config file failed");
+        std::cerr << "Parsing config file failed"
+                  << "\n";
         return;
     }