PLDM: Implementing Phosphor-Logging/LG2 logging

This commit adds changes in PLDM for implementing
structured LG2 logging, thereby moving away from
std::cout/cerr practice of logging which are
output streams and not logging mechanism.

PLDM now can make use of lg2 features like accurate
CODE LINE Number and CODE_FUNCTION Name and better
detailing in json object values which can be used in
log tracking.

More detailed logging change:
https://gist.github.com/riyadixitagra/c251685c1ba84248181891f7bc282395

Tested:
Ran a power off, on, cycle, and reset-reload.

Change-Id: I0485035f15f278c3fd172f0581b053c1c37f3a5b
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/oem/ibm/libpldmresponder/file_io.cpp b/oem/ibm/libpldmresponder/file_io.cpp
index acf9d4a..96a1c71 100644
--- a/oem/ibm/libpldmresponder/file_io.cpp
+++ b/oem/ibm/libpldmresponder/file_io.cpp
@@ -14,11 +14,15 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <cstring>
 #include <fstream>
 #include <iostream>
 #include <memory>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 using namespace pldm::responder::utils;
@@ -67,9 +71,9 @@
     if (dmaFd < 0)
     {
         rc = -errno;
-        std::cerr << "transferHostDataToSocket: Failed to open the XDMA device,"
-                     " RC="
-                  << rc << "\n";
+        error(
+            "transferHostDataToSocket: Failed to open the XDMA device, RC={RC}",
+            "RC", rc);
         return rc;
     }
 
@@ -81,9 +85,9 @@
     if (MAP_FAILED == vgaMem)
     {
         rc = -errno;
-        std::cerr << "transferHostDataToSocket: Failed to mmap the XDMA device,"
-                     " RC="
-                  << rc << "\n";
+        error(
+            "transferHostDataToSocket : Failed to mmap the XDMA device, RC={RC}",
+            "RC", rc);
         return rc;
     }
 
@@ -98,10 +102,9 @@
     if (rc < 0)
     {
         rc = -errno;
-        std::cerr << "transferHostDataToSocket: Failed to execute the DMA "
-                     "operation, RC="
-                  << rc << " ADDRESS=" << address << " LENGTH=" << length
-                  << "\n";
+        error(
+            "transferHostDataToSocket: Failed to execute the DMA operation, RC={RC} ADDRESS={ADDR} LENGTH={LEN}",
+            "RC", rc, "ADDR", address, "LEN", length);
         return rc;
     }
 
@@ -111,9 +114,9 @@
     {
         rc = -errno;
         close(fd);
-        std::cerr << "transferHostDataToSocket: Closing socket as "
-                     "writeToUnixSocket faile with RC="
-                  << rc << std::endl;
+        error(
+            "transferHostDataToSocket: Closing socket as writeToUnixSocket faile with RC={RC}",
+            "RC", rc);
         return rc;
     }
     return 0;
@@ -139,10 +142,8 @@
         }
         else
         {
-            std::cerr
-                << "transferDataHost: Received interrupt during DMA transfer."
-                   " Skipping Unmap."
-                << std::endl;
+            error(
+                "transferDataHost: Received interrupt during DMA transfer. Skipping Unmap.");
         }
     };
 
@@ -151,8 +152,8 @@
     if (dmaFd < 0)
     {
         rc = -errno;
-        std::cerr << "transferDataHost: Failed to open the XDMA device, RC="
-                  << rc << "\n";
+        error("transferDataHost : Failed to open the XDMA device, RC={RC}",
+              "RC", rc);
         return rc;
     }
 
@@ -164,8 +165,8 @@
     if (MAP_FAILED == vgaMem)
     {
         rc = -errno;
-        std::cerr << "transferDataHost: Failed to mmap the XDMA device, RC="
-                  << rc << "\n";
+        error("transferDataHost : Failed to mmap the XDMA device, RC={RC}",
+              "RC", rc);
         return rc;
     }
 
@@ -176,9 +177,9 @@
         rc = lseek(fd, offset, SEEK_SET);
         if (rc == -1)
         {
-            std::cerr << "transferDataHost upstream: lseek failed, ERROR="
-                      << errno << ", UPSTREAM=" << upstream
-                      << ", OFFSET=" << offset << "\n";
+            error(
+                "transferDataHost upstream : lseek failed, ERROR={ERR}, UPSTREAM={UPSTREAM}, OFFSET={OFFSET}",
+                "ERR", errno, "UPSTREAM", upstream, "OFFSET", offset);
             return rc;
         }
 
@@ -190,16 +191,17 @@
         rc = read(fd, buffer.data(), length);
         if (rc == -1)
         {
-            std::cerr << "transferDataHost upstream: file read failed, ERROR="
-                      << errno << ", UPSTREAM=" << upstream
-                      << ", LENGTH=" << length << ", OFFSET=" << offset << "\n";
+            error(
+                "transferDataHost upstream : file read failed, ERROR={ERR}, UPSTREAM={UPSTREAM}, LENGTH={LEN}, OFFSET={OFFSET}",
+                "ERR", errno, "UPSTREAM", upstream, "LEN", length, "OFFSET",
+                offset);
             return rc;
         }
         if (rc != static_cast<int>(length))
         {
-            std::cerr << "transferDataHost upstream: mismatch between number of"
-                      << "characters to read and the length read, LENGTH="
-                      << length << " COUNT=" << rc << "\n";
+            error(
+                "transferDataHost upstream : mismatch between number of characters to read and the length read, LENGTH={LEN} COUNT={RC}",
+                "LEN", length, "RC", rc);
             return -1;
         }
         memcpy(static_cast<char*>(vgaMemPtr.get()), buffer.data(),
@@ -215,10 +217,9 @@
     if (rc < 0)
     {
         rc = -errno;
-        std::cerr << "transferDataHost: Failed to execute the DMA operation,"
-                     " RC="
-                  << rc << " UPSTREAM=" << upstream << " ADDRESS=" << address
-                  << " LENGTH=" << length << "\n";
+        error(
+            "transferDataHost : Failed to execute the DMA operation, RC={RC} UPSTREAM={UPSTREAM} ADDRESS={ADDR} LENGTH={LEN}",
+            "RC", rc, "UPSTREAM", upstream, "ADDR", address, "LEN", length);
         return rc;
     }
 
@@ -227,18 +228,18 @@
         rc = lseek(fd, offset, SEEK_SET);
         if (rc == -1)
         {
-            std::cerr << "transferDataHost downstream: lseek failed, ERROR="
-                      << errno << ", UPSTREAM=" << upstream
-                      << ", OFFSET=" << offset << "\n";
+            error(
+                "transferDataHost downstream : lseek failed, ERROR={ERR}, UPSTREAM={UPSTREAM}, OFFSET={OFFSET}",
+                "ERR", errno, "UPSTREAM", upstream, "OFFSET", offset);
             return rc;
         }
         rc = write(fd, static_cast<const char*>(vgaMemPtr.get()), length);
         if (rc == -1)
         {
-            std::cerr << "transferDataHost downstream: file write failed,"
-                         " ERROR="
-                      << errno << ", UPSTREAM=" << upstream
-                      << ", LENGTH=" << length << ", OFFSET=" << offset << "\n";
+            error(
+                "transferDataHost downstream : file write failed, ERROR={ERR}, UPSTREAM={UPSTREAM}, LENGTH={LEN}, OFFSET={OFFSET}",
+                "ERR", errno, "UPSTREAM", upstream, "LEN", length, "OFFSET",
+                offset);
             return rc;
         }
     }
@@ -282,8 +283,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "File handle does not exist in the file table, HANDLE="
-                  << fileHandle << "\n";
+        error(
+            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
+            "FILE_HANDLE", fileHandle);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -292,7 +294,8 @@
 
     if (!fs::exists(value.fsPath))
     {
-        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
+        error("File does not exist, HANDLE={FILE_HANDLE}", "FILE_HANDLE",
+              fileHandle);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -302,8 +305,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                  << " FILE_SIZE=" << fileSize << "\n";
+        error("Offset exceeds file size, OFFSET={OFFSTE} FILE_SIZE={FILE_SIZE}",
+              "OFFSET", offset, "FILE_SIZE", fileSize);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
@@ -317,8 +320,8 @@
 
     if (length % dma::minSize)
     {
-        std::cerr << "Read length is not a multiple of DMA minSize, LENGTH="
-                  << length << "\n";
+        error("Read length is not a multiple of DMA minSize, LENGTH={LEN}",
+              "LEN", length);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
@@ -356,8 +359,8 @@
 
     if (length % dma::minSize)
     {
-        std::cerr << "Write length is not a multiple of DMA minSize, LENGTH="
-                  << length << "\n";
+        error("Write length is not a multiple of DMA minSize, LENGTH={LEN}",
+              "LEN", length);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_ERROR_INVALID_LENGTH, 0, responsePtr);
@@ -374,8 +377,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "File handle does not exist in the file table, HANDLE="
-                  << fileHandle << "\n";
+        error(
+            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
+            "FILE_HANDLE", fileHandle);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -384,7 +388,8 @@
 
     if (!fs::exists(value.fsPath))
     {
-        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
+        error("File does not exist, HANDLE={FILE_HANDLE}", "FILE_HANDLE",
+              fileHandle);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -394,8 +399,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                  << " FILE_SIZE=" << fileSize << "\n";
+        error("Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+              "OFFSET", offset, "FILE_SIZE", fileSize);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_DATA_OUT_OF_RANGE, 0, responsePtr);
@@ -499,8 +504,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "File handle does not exist in the file table, HANDLE="
-                  << fileHandle << "\n";
+        error(
+            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
+            "FILE_HANDLE", fileHandle);
         encode_read_file_resp(request->hdr.instance_id,
                               PLDM_INVALID_FILE_HANDLE, length, responsePtr);
         return response;
@@ -508,7 +514,8 @@
 
     if (!fs::exists(value.fsPath))
     {
-        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
+        error("File does not exist, HANDLE={FILE_HANDLE}", "FILE_HANDLE",
+              fileHandle);
         encode_read_file_resp(request->hdr.instance_id,
                               PLDM_INVALID_FILE_HANDLE, length, responsePtr);
         return response;
@@ -517,8 +524,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                  << " FILE_SIZE=" << fileSize << "\n";
+        error("Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+              "OFFSET", offset, "FILE_SIZE", fileSize);
         encode_read_file_resp(request->hdr.instance_id, PLDM_DATA_OUT_OF_RANGE,
                               length, responsePtr);
         return response;
@@ -580,8 +587,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "File handle does not exist in the file table, HANDLE="
-                  << fileHandle << "\n";
+        error(
+            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
+            "FILE_HANDLE", fileHandle);
         encode_write_file_resp(request->hdr.instance_id,
                                PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
         return response;
@@ -589,7 +597,8 @@
 
     if (!fs::exists(value.fsPath))
     {
-        std::cerr << "File does not exist, HANDLE=" << fileHandle << "\n";
+        error("File does not exist, HANDLE={FILE_HANDLE}", "FILE_HANDLE",
+              fileHandle);
         encode_write_file_resp(request->hdr.instance_id,
                                PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
         return response;
@@ -598,8 +607,8 @@
     auto fileSize = fs::file_size(value.fsPath);
     if (offset >= fileSize)
     {
-        std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                  << " FILE_SIZE=" << fileSize << "\n";
+        error("Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+              "OFFSET", offset, "FILE_SIZE", fileSize);
         encode_write_file_resp(request->hdr.instance_id, PLDM_DATA_OUT_OF_RANGE,
                                0, responsePtr);
         return response;
@@ -651,8 +660,8 @@
     }
     if (length % dma::minSize)
     {
-        std::cerr << "Length is not a multiple of DMA minSize, LENGTH="
-                  << length << "\n";
+        error("Length is not a multiple of DMA minSize, LENGTH={LEN}", "LEN",
+              length);
         encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
                                            PLDM_ERROR_INVALID_LENGTH, 0,
                                            responsePtr);
@@ -666,7 +675,7 @@
     }
     catch (const InternalFailure& e)
     {
-        std::cerr << "unknown file type, TYPE=" << fileType << "\n";
+        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
         encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
                                            PLDM_INVALID_FILE_TYPE, 0,
                                            responsePtr);
@@ -731,7 +740,7 @@
     }
     catch (const InternalFailure& e)
     {
-        std::cerr << "unknown file type, TYPE=" << fileType << "\n";
+        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
         encode_rw_file_by_type_resp(request->hdr.instance_id,
                                     PLDM_WRITE_FILE_BY_TYPE,
                                     PLDM_INVALID_FILE_TYPE, 0, responsePtr);
@@ -780,7 +789,7 @@
     }
     catch (const InternalFailure& e)
     {
-        std::cerr << "unknown file type, TYPE=" << fileType << "\n";
+        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
         encode_rw_file_by_type_resp(request->hdr.instance_id,
                                     PLDM_READ_FILE_BY_TYPE,
                                     PLDM_INVALID_FILE_TYPE, 0, responsePtr);
@@ -900,7 +909,7 @@
     }
     catch (const InternalFailure& e)
     {
-        std::cerr << "unknown file type, TYPE=" << fileType << "\n";
+        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
         return CmdHandler::ccOnlyResponse(request, PLDM_INVALID_FILE_TYPE);
     }
 
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 769e716..ddde7f8 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -17,17 +17,20 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <filesystem>
 #include <iostream>
 #include <vector>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
 {
 namespace dma
 {
-
 // The minimum data size of dma transfer in bytes
 constexpr uint32_t minSize = 16;
 
@@ -116,7 +119,8 @@
     int file = open(path.string().c_str(), flags);
     if (file == -1)
     {
-        std::cerr << "File does not exist, path = " << path.string() << "\n";
+        error("File does not exist, path = {FILE_PATH}", "FILE_PATH",
+              path.string());
         encode_rw_file_memory_resp(instanceId, command, PLDM_ERROR, 0,
                                    responsePtr);
         return response;
diff --git a/oem/ibm/libpldmresponder/file_io_by_type.cpp b/oem/ibm/libpldmresponder/file_io_by_type.cpp
index dc575d2..ec001fa 100644
--- a/oem/ibm/libpldmresponder/file_io_by_type.cpp
+++ b/oem/ibm/libpldmresponder/file_io_by_type.cpp
@@ -15,6 +15,7 @@
 #include <stdint.h>
 #include <unistd.h>
 
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
 
 #include <exception>
@@ -23,6 +24,8 @@
 #include <iostream>
 #include <vector>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
@@ -79,15 +82,17 @@
         fileExists = fs::exists(path);
         if (!fileExists)
         {
-            std::cerr << "File does not exist. PATH=" << path.c_str() << "\n";
+            error("File does not exist. PATH={FILE_PATH}", "FILE_PATH",
+                  path.c_str());
             return PLDM_INVALID_FILE_HANDLE;
         }
 
         size_t fileSize = fs::file_size(path);
         if (offset >= fileSize)
         {
-            std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                      << " FILE_SIZE=" << fileSize << "\n";
+            error(
+                "Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+                "OFFSET", offset, "FILE_SIZE", fileSize);
             return PLDM_DATA_OUT_OF_RANGE;
         }
         if (offset + length > fileSize)
@@ -112,8 +117,8 @@
     int file = open(path.string().c_str(), flags);
     if (file == -1)
     {
-        std::cerr << "File does not exist, PATH = " << path.string() << "\n";
-        ;
+        error("File does not exist, PATH = {FILE_PATH}", "FILE_PATH",
+              path.string());
         return PLDM_ERROR;
     }
     utils::CustomFD fd(file);
@@ -178,16 +183,16 @@
 {
     if (!fs::exists(filePath))
     {
-        std::cerr << "File does not exist, HANDLE=" << fileHandle
-                  << " PATH=" << filePath.c_str() << "\n";
+        error("File does not exist, HANDLE={FILE_HANDLE} PATH={FILE_PATH}",
+              "FILE_HANDLE", fileHandle, "FILE_PATH", filePath.c_str());
         return PLDM_INVALID_FILE_HANDLE;
     }
 
     size_t fileSize = fs::file_size(filePath);
     if (offset >= fileSize)
     {
-        std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                  << " FILE_SIZE=" << fileSize << "\n";
+        error("Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+              "OFFSET", offset, "FILE_SIZE", fileSize);
         return PLDM_DATA_OUT_OF_RANGE;
     }
 
@@ -207,7 +212,8 @@
         stream.read(filePos, length);
         return PLDM_SUCCESS;
     }
-    std::cerr << "Unable to read file, FILE=" << filePath.c_str() << "\n";
+    error("Unable to read file, FILE={FILE_PATH}", "FILE_PATH",
+          filePath.c_str());
     return PLDM_ERROR;
 }
 
diff --git a/oem/ibm/libpldmresponder/file_io_type_cert.cpp b/oem/ibm/libpldmresponder/file_io_type_cert.cpp
index d396abe..8d9b73e 100644
--- a/oem/ibm/libpldmresponder/file_io_type_cert.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_cert.cpp
@@ -6,8 +6,12 @@
 #include <libpldm/file_io.h>
 #include <stdint.h>
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <iostream>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 using namespace utils;
@@ -27,8 +31,9 @@
     auto it = certMap.find(certType);
     if (it == certMap.end())
     {
-        std::cerr << "CertHandler::writeFromMemory:file for type " << certType
-                  << " doesn't exist\n";
+        error(
+            "CertHandler::writeFromMemory:file for type {CERT_TYPE} doesn't exist",
+            "CERT_TYPE", certType);
         return PLDM_ERROR;
     }
 
@@ -69,9 +74,9 @@
 int CertHandler::read(uint32_t offset, uint32_t& length, Response& response,
                       oem_platform::Handler* /*oemPlatformHandler*/)
 {
-    std::cout
-        << "CertHandler::read:Read file response for Sign CSR, file handle: "
-        << fileHandle << std::endl;
+    info(
+        "CertHandler::read:Read file response for Sign CSR, file handle: {FILE_HANDLE}",
+        "FILE_HANDLE", fileHandle);
     std::string filePath = certFilePath;
     filePath += "CSR_" + std::to_string(fileHandle);
     if (certType != PLDM_FILE_TYPE_CERT_SIGNING_REQUEST)
@@ -93,8 +98,8 @@
     auto it = certMap.find(certType);
     if (it == certMap.end())
     {
-        std::cerr << "CertHandler::write:file for type " << certType
-                  << " doesn't exist\n";
+        error("CertHandler::write:file for type {CERT_TYPE} doesn't exist",
+              "CERT_TYPE", certType);
         return PLDM_ERROR;
     }
 
@@ -102,15 +107,16 @@
     int rc = lseek(fd, offset, SEEK_SET);
     if (rc == -1)
     {
-        std::cerr << "CertHandler::write:lseek failed, ERROR=" << errno
-                  << ", OFFSET=" << offset << "\n";
+        error("CertHandler::write:lseek failed, ERROR={ERR}, OFFSET={OFFSET}",
+              "ERR", errno, "OFFSET", offset);
         return PLDM_ERROR;
     }
     rc = ::write(fd, buffer, length);
     if (rc == -1)
     {
-        std::cerr << "CertHandler::write:file write failed, ERROR=" << errno
-                  << ", LENGTH=" << length << ", OFFSET=" << offset << "\n";
+        error(
+            "CertHandler::write:file write failed, ERROR={ERR}, LENGTH={LEN}, OFFSET={OFFSET}",
+            "ERR", errno, "LEN", length, "OFFSET", offset);
         return PLDM_ERROR;
     }
     length = rc;
@@ -150,10 +156,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr
-                    << "CertHandler::write:failed to set Client certificate, "
-                       "ERROR="
-                    << e.what() << "\n";
+                error(
+                    "CertHandler::write:failed to set Client certificate, ERROR={ERR_EXCEP}",
+                    "ERR_EXCEP", e.what());
                 return PLDM_ERROR;
             }
             PropertyValue valueStatus{
@@ -163,18 +168,17 @@
                                           certEntryIntf, "Status", "string"};
             try
             {
-                std::cout
-                    << "CertHandler::write:Client cert write, status: complete. File handle: "
-                    << fileHandle << std::endl;
+                info(
+                    "CertHandler::write:Client cert write, status: complete. File handle: {FILE_HANDLE}",
+                    "FILE_HANDLE", fileHandle);
                 pldm::utils::DBusHandler().setDbusProperty(dbusMappingStatus,
                                                            valueStatus);
             }
             catch (const std::exception& e)
             {
-                std::cerr
-                    << "CertHandler::write:failed to set status property of certicate entry, "
-                       "ERROR="
-                    << e.what() << "\n";
+                error(
+                    "CertHandler::write:failed to set status property of certicate entry, ERROR={ERR_EXCEP}",
+                    "ERR_EXCEP", e.what());
                 return PLDM_ERROR;
             }
             fs::remove(filePath);
@@ -186,17 +190,16 @@
                                     certEntryIntf, "Status", "string"};
             try
             {
-                std::cout
-                    << "CertHandler::write:Client cert write, status: Bad CSR. File handle: "
-                    << fileHandle << std::endl;
+                info(
+                    "CertHandler::write:Client cert write, status: Bad CSR. File handle: {FILE_HANDLE}",
+                    "FILE_HANDLE", fileHandle);
                 pldm::utils::DBusHandler().setDbusProperty(dbusMapping, value);
             }
             catch (const std::exception& e)
             {
-                std::cerr
-                    << "CertHandler::write:failed to set status property of certicate entry, "
-                       "ERROR="
-                    << e.what() << "\n";
+                error(
+                    "CertHandler::write:failed to set status property of certicate entry, {ERR_EXCEP}",
+                    "ERR_EXCEP", e.what());
                 return PLDM_ERROR;
             }
         }
@@ -219,9 +222,9 @@
     }
     if (certType == PLDM_FILE_TYPE_SIGNED_CERT)
     {
-        std::cout
-            << "CertHandler::newFileAvailable:new file available client cert file, file handle: "
-            << fileHandle << std::endl;
+        info(
+            "CertHandler::newFileAvailable:new file available client cert file, file handle: {FILE_HANDLE}",
+            "FILE_HANDLE", fileHandle);
         fileFd = open(
             (filePath + "ClientCert_" + std::to_string(fileHandle)).c_str(),
             flags, S_IRUSR | S_IWUSR);
@@ -233,9 +236,9 @@
     }
     if (fileFd == -1)
     {
-        std::cerr
-            << "CertHandler::newFileAvailable:failed to open file for type "
-            << certType << " ERROR=" << errno << "\n";
+        error(
+            "CertHandler::newFileAvailable:failed to open file for type {CERT_TYPE} ERROR={ERR}",
+            "CERT_TYPE", certType, "ERR", errno);
         return PLDM_ERROR;
     }
     certMap.emplace(certType, std::tuple(fileFd, length));
@@ -263,18 +266,18 @@
     {
         if (metaDataValue1 == PLDM_SUCCESS)
         {
-            std::cerr
-                << "CertHandler::newFileAvailableWithMetaData:new file available client cert file, file handle: "
-                << fileHandle << std::endl;
+            error(
+                "CertHandler::newFileAvailableWithMetaData:new file available client cert file, file handle: {FILE_HANDLE}",
+                "FILE_HANDLE", fileHandle);
             fileFd = open(
                 (filePath + "ClientCert_" + std::to_string(fileHandle)).c_str(),
                 flags, S_IRUSR | S_IWUSR);
         }
         else if (metaDataValue1 == PLDM_INVALID_CERT_DATA)
         {
-            std::cerr
-                << "newFileAvailableWithMetaData:client cert file Invalid data, file handle: "
-                << fileHandle << std::endl;
+            error(
+                "newFileAvailableWithMetaData:client cert file Invalid data, file handle: {FILE_HANDLE}",
+                "FILE_HANDLE", fileHandle);
             DBusMapping dbusMapping{certObjPath + std::to_string(fileHandle),
                                     certEntryIntf, "Status", "string"};
             std::string status = "xyz.openbmc_project.Certs.Entry.State.BadCSR";
@@ -285,10 +288,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr
-                    << "newFileAvailableWithMetaData:Failed to set status property of certicate entry, "
-                       "ERROR="
-                    << e.what() << "\n";
+                error(
+                    "newFileAvailableWithMetaData:Failed to set status property of certicate entry, ERROR= {ERR_EXCEP}",
+                    "ERR_EXCEP", e.what());
                 return PLDM_ERROR;
             }
         }
@@ -300,9 +302,9 @@
     }
     if (fileFd == -1)
     {
-        std::cerr
-            << "newFileAvailableWithMetaData:failed to open file for type "
-            << certType << " ERROR=" << errno << "\n";
+        error(
+            "newFileAvailableWithMetaData:failed to open file for type {CERT_TYPE} ERROR={ERR}",
+            "CERT_TYPE", certType, "ERR", errno);
         return PLDM_ERROR;
     }
     certMap.emplace(certType, std::tuple(fileFd, length));
@@ -334,10 +336,9 @@
         }
         catch (const std::exception& e)
         {
-            std::cerr
-                << "CertHandler::fileAckWithMetaData:Failed to set status property of certicate entry, "
-                   "ERROR="
-                << e.what() << "\n";
+            error(
+                "CertHandler::fileAckWithMetaData:Failed to set status property of certicate entry, ERROR={ERR_EXCEP}",
+                "ERR_EXCEP", e.what());
             return PLDM_ERROR;
         }
     }
diff --git a/oem/ibm/libpldmresponder/file_io_type_dump.cpp b/oem/ibm/libpldmresponder/file_io_type_dump.cpp
index 13fe9f0..0a0e041 100644
--- a/oem/ibm/libpldmresponder/file_io_type_dump.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_dump.cpp
@@ -10,6 +10,7 @@
 #include <systemd/sd-bus.h>
 #include <unistd.h>
 
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/server.hpp>
 #include <xyz/openbmc_project/Dump/NewDump/server.hpp>
 
@@ -18,6 +19,8 @@
 #include <iostream>
 #include <type_traits>
 
+PHOSPHOR_LOG2_USING;
+
 using namespace pldm::responder::utils;
 using namespace pldm::utils;
 
@@ -71,10 +74,10 @@
     }
     catch (const sdbusplus::exception_t& e)
     {
-        std::cerr << "findDumpObjPath: Error " << e.what()
-                  << "found with GetManagedObjects call in findDumpObjPath "
-                  << "with objPath=" << DUMP_MANAGER_PATH
-                  << " and intf=" << dumpEntryIntf << "\n";
+        error(
+            "findDumpObjPath: Error {ERR_EXCEP} found with GetManagedObjects call in findDumpObjPath with objPath={OBJ_PATH} and intf={DUMP_INFT}",
+            "ERR_EXCEP", e.what(), "OBJ_PATH", DUMP_MANAGER_PATH, "DUMP_INFT",
+            dumpEntryIntf);
         return curResDumpEntryPath;
     }
 
@@ -103,11 +106,9 @@
                     }
                     else
                     {
-                        std::cerr
-                            << "Invalid SourceDumpId in curResDumpEntryPath "
-                            << curResDumpEntryPath
-                            << " but continuing with next entry for a match..."
-                            << "\n";
+                        error(
+                            "Invalid SourceDumpId in curResDumpEntryPath {CUR_RES_DUMP_PATH} but continuing with next entry for a match...",
+                            "CUR_RES_DUMP_PATH", curResDumpEntryPath);
                     }
                 }
             }
@@ -140,10 +141,10 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "newFileAvailable: Error " << e.what()
-                  << "found while notifying new dump to dump manager "
-                  << "with objPath=" << notifyObjPath
-                  << " and intf=" << dumpInterface << "\n";
+        error(
+            "newFileAvailable: Error {ERR_EXCEP} found while notifying new dump to dump manager with objPath={OBJ_PATH} and intf={DUMP_INTF}",
+            "ERR_EXCEP", e.what(), "OBJ_PATH", notifyObjPath, "DUMP_INTF",
+            dumpInterface);
         return PLDM_ERROR;
     }
 
@@ -168,10 +169,10 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "getOffloadUri: Error " << e.what()
-                  << "found while fetching the dump offload URI "
-                  << "with objPath=" << path.c_str()
-                  << " and intf=" << socketInterface << "\n";
+        error(
+            "getOffloadUri: Error {ERR_EXCEP} found while fetching the dump offload URI with objPath={OBJ_PATH} and intf={SOCKET_INTF}",
+            "ERR_EXCEP", e.what(), "OBJ_PATH", path.c_str(), "SOCKET_INTF",
+            socketInterface);
     }
 
     return socketInterface;
@@ -188,9 +189,7 @@
         {
             sock = -errno;
             close(DumpHandler::fd);
-            std::cerr
-                << "DumpHandler::writeFromMemory: setupUnixSocket() failed"
-                << std::endl;
+            error("DumpHandler::writeFromMemory: setupUnixSocket() failed");
             std::remove(socketInterface.c_str());
             return PLDM_ERROR;
         }
@@ -210,8 +209,7 @@
         close(DumpHandler::fd);
         auto socketInterface = getOffloadUri(fileHandle);
         std::remove(socketInterface.c_str());
-        std::cerr << "DumpHandler::write: writeToUnixSocket() failed"
-                  << std::endl;
+        error("DumpHandler::write: writeToUnixSocket() failed");
         return PLDM_ERROR;
     }
 
@@ -225,7 +223,7 @@
     {
         if (fileStatus != PLDM_SUCCESS)
         {
-            std::cerr << "Failue in resource dump file ack" << std::endl;
+            error("Failue in resource dump file ack");
             pldm::utils::reportError(
                 "xyz.openbmc_project.bmc.pldm.InternalFailure");
 
@@ -239,11 +237,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr << "fileAck: Error " << e.what()
-                          << "found while setting the dump progress status as "
-                          << "Failed with objPath=" << path.c_str()
-                          << " and intf=Common.Progress"
-                          << "\n";
+                error(
+                    "fileAck: Error {ERR_EXCEP} found while setting the dump progress status as Failed with objPath={OBJ_PATH} and intf=Common.Progress",
+                    "ERR_EXCEP", e.what(), "OBJ_PATH", path.c_str());
             }
         }
 
@@ -275,10 +271,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr << "fileAck: Failed to make a d-bus call to DUMP "
-                             "manager to reset source dump id of "
-                          << path.c_str() << ", with ERROR=" << e.what()
-                          << "\n";
+                error(
+                    "fileAck: Failed to make a d-bus call to DUMP manager to reset source dump id of {FILE_PATH}, with ERROR={ERR_EXCEP}",
+                    "FILE_PATH", path.c_str(), "ERR_EXCEP", e.what());
                 pldm::utils::reportError(
                     "xyz.openbmc_project.bmc.PLDM.fileAck.SourceDumpIdResetFail");
                 return PLDM_ERROR;
@@ -294,9 +289,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr
-                    << "fileAck: Failed to make a d-bus method to delete the dump entry "
-                    << path.c_str() << ", with ERROR=" << e.what() << "\n";
+                error(
+                    "fileAck: Failed to make a d-bus method to delete the dump entry {FILE_PATH}, with ERROR={ERR_EXCEP}",
+                    "FILE_PATH", path.c_str(), "ERR_EXCEP", e.what());
                 pldm::utils::reportError(
                     "xyz.openbmc_project.bmc.PLDM.fileAck.DumpEntryDeleteFail");
                 return PLDM_ERROR;
@@ -315,10 +310,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr
-                    << "fileAck: Failed to make a d-bus method to set the dump "
-                    << "offloaded property to true with path=" << path.c_str()
-                    << "and with ERROR=" << e.what() << "\n";
+                error(
+                    "fileAck: Failed to make a d-bus method to set the dump offloaded property to true with path={FILE_PATH} and with ERROR={ERR_EXCEP}",
+                    "FILE_PATH", path.c_str(), "ERR_EXCEP", e.what());
             }
 
             auto socketInterface = getOffloadUri(fileHandle);
diff --git a/oem/ibm/libpldmresponder/file_io_type_lid.hpp b/oem/ibm/libpldmresponder/file_io_type_lid.hpp
index 0853d48..dbb4fc7 100644
--- a/oem/ibm/libpldmresponder/file_io_type_lid.hpp
+++ b/oem/ibm/libpldmresponder/file_io_type_lid.hpp
@@ -4,10 +4,14 @@
 
 #include "file_io_by_type.hpp"
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <filesystem>
 #include <sstream>
 #include <string>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
@@ -127,8 +131,8 @@
         auto fd = open(lidPath.c_str(), flags, S_IRUSR);
         if (fd == -1)
         {
-            std::cerr << "Could not open file for writing  " << lidPath.c_str()
-                      << "\n";
+            error("Could not open file for writing  {LID_PATH}", "LID_PATH",
+                  lidPath.c_str());
             return PLDM_ERROR;
         }
         close(fd);
@@ -136,7 +140,7 @@
         rc = transferFileData(lidPath, false, offset, length, address);
         if (rc != PLDM_SUCCESS)
         {
-            std::cerr << "writeFileFromMemory failed with rc= " << rc << " \n";
+            error("writeFileFromMemory failed with rc= {RC}", "RC", rc);
             return rc;
         }
         if (lidType == PLDM_FILE_TYPE_LID_MARKER)
@@ -204,8 +208,9 @@
             size_t fileSize = fs::file_size(lidPath);
             if (offset > fileSize)
             {
-                std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                          << " FILE_SIZE=" << fileSize << "\n";
+                error(
+                    "Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+                    "OFFSET", offset, "FILE_SIZE", fileSize);
                 return PLDM_DATA_OUT_OF_RANGE;
             }
         }
@@ -214,28 +219,30 @@
             flags = O_WRONLY | O_CREAT | O_TRUNC | O_SYNC;
             if (offset > 0)
             {
-                std::cerr << "Offset is non zero in a new file \n";
+                error("Offset is non zero in a new file");
                 return PLDM_DATA_OUT_OF_RANGE;
             }
         }
         auto fd = open(lidPath.c_str(), flags, S_IRUSR);
         if (fd == -1)
         {
-            std::cerr << "could not open file " << lidPath.c_str() << "\n";
+            error("could not open file {LID_PATH}", "LID_PATH",
+                  lidPath.c_str());
             return PLDM_ERROR;
         }
         rc = lseek(fd, offset, SEEK_SET);
         if (rc == -1)
         {
-            std::cerr << "lseek failed, ERROR=" << errno
-                      << ", OFFSET=" << offset << "\n";
+            error("lseek failed, ERROR={ERR}, OFFSET={OFFSET}", "ERR", errno,
+                  "OFFSET", offset);
             return PLDM_ERROR;
         }
         rc = ::write(fd, buffer, length);
         if (rc == -1)
         {
-            std::cerr << "file write failed, ERROR=" << errno
-                      << ", LENGTH=" << length << ", OFFSET=" << offset << "\n";
+            error(
+                "file write failed, ERROR={ERR}, LENGTH={LEN}, OFFSET={OFFSET}",
+                "ERR", errno, "LEN", length, "OFFSET", offset);
             return PLDM_ERROR;
         }
         else if (rc == static_cast<int>(length))
diff --git a/oem/ibm/libpldmresponder/file_io_type_pel.cpp b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
index 8374abf..2bbb5af 100644
--- a/oem/ibm/libpldmresponder/file_io_type_pel.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
@@ -11,6 +11,7 @@
 #include <systemd/sd-bus.h>
 #include <unistd.h>
 
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/server.hpp>
 #include <xyz/openbmc_project/Logging/Entry/server.hpp>
 
@@ -20,16 +21,16 @@
 #include <iostream>
 #include <vector>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
 {
-
 using namespace sdbusplus::xyz::openbmc_project::Logging::server;
 
 namespace detail
 {
-
 /**
  * @brief Finds the Entry::Level value for the severity of the PEL
  *        passed in.
@@ -82,7 +83,8 @@
         }
         else
         {
-            std::cerr << "Unable to open PEL file " << pelFileName << "\n";
+            error("Unable to open PEL file {PEL_FILE_NAME}", "PEL_FILE_NAME",
+                  pelFileName);
         }
     }
 
@@ -114,8 +116,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "GetPEL D-Bus call failed, PEL id = 0x" << std::hex
-                  << fileHandle << ", error = " << e.what() << "\n";
+        error(
+            "GetPEL D-Bus call failed, PEL id = 0x{FILE_HANDLE}, error ={ERR_EXCEP}",
+            "FILE_HANDLE", lg2::hex, fileHandle, "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }
 
@@ -143,13 +146,14 @@
         off_t fileSize = lseek(fd, 0, SEEK_END);
         if (fileSize == -1)
         {
-            std::cerr << "file seek failed";
+            error("file seek failed");
             return PLDM_ERROR;
         }
         if (offset >= fileSize)
         {
-            std::cerr << "Offset exceeds file size, OFFSET=" << offset
-                      << " FILE_SIZE=" << fileSize << std::endl;
+            error(
+                "Offset exceeds file size, OFFSET={OFFSET} FILE_SIZE={FILE_SIZE}",
+                "OFFSET", offset, "FILE_SIZE", fileSize);
             return PLDM_DATA_OUT_OF_RANGE;
         }
         if (offset + length > fileSize)
@@ -159,7 +163,7 @@
         auto rc = lseek(fd, offset, SEEK_SET);
         if (rc == -1)
         {
-            std::cerr << "file seek failed";
+            error("file seek failed");
             return PLDM_ERROR;
         }
         size_t currSize = response.size();
@@ -169,21 +173,22 @@
         rc = ::read(fd, filePos, length);
         if (rc == -1)
         {
-            std::cerr << "file read failed";
+            error("file read failed");
             return PLDM_ERROR;
         }
         if (rc != length)
         {
-            std::cerr << "mismatch between number of characters to read and "
-                      << "the length read, LENGTH=" << length << " COUNT=" << rc
-                      << std::endl;
+            error(
+                "mismatch between number of characters to read and the length read, LENGTH={LEN} COUNT={CNT}",
+                "LEN", length, "CNT", rc);
             return PLDM_ERROR;
         }
     }
     catch (const std::exception& e)
     {
-        std::cerr << "GetPEL D-Bus call failed on PEL ID 0x" << std::hex
-                  << fileHandle << ", error = " << e.what() << "\n";
+        error(
+            "GetPEL D-Bus call failed on PEL ID 0x{FILE_HANDLE}, error ={ERR_EXCEP}",
+            "FILE_HANDLE", lg2::hex, fileHandle, "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }
     return PLDM_SUCCESS;
@@ -197,8 +202,7 @@
     int fd = mkstemp(tmpFile);
     if (fd == -1)
     {
-        std::cerr << "failed to create a temporary pel, ERROR=" << errno
-                  << "\n";
+        error("failed to create a temporary pel, ERROR={ERR}", "ERR", errno);
         return PLDM_ERROR;
     }
     close(fd);
@@ -229,8 +233,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "HostAck D-Bus call failed on PEL ID 0x" << std::hex
-                  << fileHandle << ", error = " << e.what() << "\n";
+        error(
+            "HostAck D-Bus call failed on PEL ID 0x{FILE_HANDLE}, error ={ERR_EXCEP}",
+            "FILE_HANDLE", lg2::hex, fileHandle, "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }
 
@@ -263,8 +268,8 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "failed to make a d-bus call to PEL daemon, ERROR="
-                  << e.what() << "\n";
+        error("failed to make a d-bus call to PEL daemon, ERROR={ERR_EXCEP}",
+              "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }
 
@@ -278,7 +283,7 @@
 
     if (offset > 0)
     {
-        std::cerr << "Offset is non zero \n";
+        error("Offset is non zero");
         return PLDM_ERROR;
     }
 
@@ -286,8 +291,7 @@
     auto fd = mkstemp(tmpFile);
     if (fd == -1)
     {
-        std::cerr << "failed to create a temporary pel, ERROR=" << errno
-                  << "\n";
+        error("failed to create a temporary pel, ERROR={ERR}", "ERR", errno);
         return PLDM_ERROR;
     }
 
@@ -305,8 +309,8 @@
 
     if (rc == -1)
     {
-        std::cerr << "file write failed, ERROR=" << errno
-                  << ", LENGTH=" << length << ", OFFSET=" << offset << "\n";
+        error("file write failed, ERROR={ERR}, LENGTH={LEN}, OFFSET={OFFSET}",
+              "ERR", errno, "LEN", length, "OFFSET", offset);
         fs::remove(tmpFile);
         return PLDM_ERROR;
     }
@@ -317,8 +321,8 @@
         rc = storePel(path.string());
         if (rc != PLDM_SUCCESS)
         {
-            std::cerr << "save PEL failed, ERROR = " << rc
-                      << "tmpFile = " << tmpFile << "\n";
+            error("save PEL failed, ERROR = {RC} tmpFile = {TMP_FILE}", "RC",
+                  rc, "TMP_FILE", tmpFile);
         }
     }
 
diff --git a/oem/ibm/libpldmresponder/file_io_type_progress_src.cpp b/oem/ibm/libpldmresponder/file_io_type_progress_src.cpp
index 836a840..93a6680 100644
--- a/oem/ibm/libpldmresponder/file_io_type_progress_src.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_progress_src.cpp
@@ -2,6 +2,10 @@
 
 #include "common/utils.hpp"
 
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 
@@ -35,8 +39,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "failed to make a d-bus call to host-postd daemon, ERROR="
-                  << e.what() << "\n";
+        error(
+            "failed to make a d-bus call to host-postd daemon, ERROR={ERR_EXCEP}",
+            "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }
 
diff --git a/oem/ibm/libpldmresponder/file_table.cpp b/oem/ibm/libpldmresponder/file_table.cpp
index 594adc7..5c2a2da 100644
--- a/oem/ibm/libpldmresponder/file_table.cpp
+++ b/oem/ibm/libpldmresponder/file_table.cpp
@@ -2,30 +2,31 @@
 
 #include <libpldm/utils.h>
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <fstream>
 #include <iostream>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
-
 namespace filetable
 {
-
 FileTable::FileTable(const std::string& fileTableConfigPath)
 {
     std::ifstream jsonFile(fileTableConfigPath);
     if (!jsonFile.is_open())
     {
-        std::cerr << "File table config file does not exist, FILE="
-                  << fileTableConfigPath.c_str() << "\n";
+        error("File table config file does not exist, FILE={TABLE_CONFIG_PATH}",
+              "TABLE_CONFIG_PATH", fileTableConfigPath.c_str());
         return;
     }
 
     auto data = Json::parse(jsonFile, nullptr, false);
     if (data.is_discarded())
     {
-        std::cerr << "Parsing config file failed"
-                  << "\n";
+        error("Parsing config file failed");
         return;
     }
 
diff --git a/oem/ibm/libpldmresponder/inband_code_update.cpp b/oem/ibm/libpldmresponder/inband_code_update.cpp
index 3066b40..c995fc1 100644
--- a/oem/ibm/libpldmresponder/inband_code_update.cpp
+++ b/oem/ibm/libpldmresponder/inband_code_update.cpp
@@ -7,11 +7,15 @@
 #include <arpa/inet.h>
 #include <libpldm/entity.h>
 
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/server.hpp>
 #include <xyz/openbmc_project/Dump/NewDump/server.hpp>
 
 #include <exception>
 #include <fstream>
+
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 using namespace utils;
@@ -75,7 +79,7 @@
     }
     if (objPath.empty())
     {
-        std::cerr << "no nonRunningVersion present \n";
+        error("no nonRunningVersion present");
         return PLDM_PLATFORM_INVALID_STATE_VALUE;
     }
 
@@ -89,8 +93,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "failed to set the next boot side to " << objPath.c_str()
-                  << " ERROR=" << e.what() << "\n";
+        error(
+            "failed to set the next boot side to {OBJ_PATH} ERROR={ERR_EXCEP}",
+            "OBJ_PATH", objPath.c_str(), "ERR_EXCEP", e.what());
         return PLDM_ERROR;
     }
     return PLDM_SUCCESS;
@@ -112,8 +117,8 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Failed To set RequestedApplyTime property "
-                  << "ERROR=" << e.what() << std::endl;
+        error("Failed To set RequestedApplyTime property ERROR={ERR_EXCEP}",
+              "ERR_EXCEP", e.what());
         rc = PLDM_ERROR;
     }
     return rc;
@@ -135,8 +140,8 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Failed To set RequestedActivation property"
-                  << "ERROR=" << e.what() << std::endl;
+        error("Failed To set RequestedActivation property ERROR={ERR_EXCEP}",
+              "ERR_EXCEP", e.what());
         rc = PLDM_ERROR;
     }
     return rc;
@@ -181,9 +186,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "failed to make a d-bus call to Object Mapper "
-                     "Association, ERROR="
-                  << e.what() << "\n";
+        error(
+            "failed to make a d-bus call to Object Mapper Association, ERROR={ERR_EXCEP}",
+            "ERR_EXCEP", e.what());
         return;
     }
 
@@ -299,15 +304,17 @@
                                     sensorId, PLDM_STATE_SENSOR_STATE, 0,
                                     uint8_t(state),
                                     uint8_t(CodeUpdateState::START));
-                                std::cerr
-                                    << "could not set RequestedActivation \n";
+                                error("could not set RequestedActivation");
                             }
                             break;
                         }
                     }
                     catch (const sdbusplus::exception_t& e)
                     {
-                        std::cerr << "Error in getting Activation status \n";
+                        error(
+                            "Error in getting Activation status,ERROR= {ERR_EXCEP}, INTERFACE={IMG_INTERFACE}, OBJECT PATH={OBJ_PATH}",
+                            "ERR_EXCEP", e.what(), "IMG_INTERFACE",
+                            imageInterface, "OBJ_PATH", imageObjPath);
                     }
                 }
             }
@@ -338,8 +345,8 @@
 {
     if (!fs::is_directory(dirPath))
     {
-        std::cerr << "The directory does not exist, dirPath = " << dirPath
-                  << std::endl;
+        error("The directory does not exist, dirPath = {DIR_PATH}", "DIR_PATH",
+              dirPath.c_str());
         return;
     }
     for (const auto& iter : fs::directory_iterator(dirPath))
@@ -376,7 +383,8 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Failed to delete image, ERROR=" << e.what() << "\n";
+        error("Failed to delete image, ERROR={ERR_EXCEP}", "ERR_EXCEP",
+              e.what());
         return;
     }
 }
@@ -471,7 +479,7 @@
     std::ifstream ifs(filePath, std::ios::in | std::ios::binary);
     if (!ifs)
     {
-        std::cerr << "ifstream open error: " << filePath << "\n";
+        error("ifstream open error: {DIR_PATH}", "DIR_PATH", filePath.c_str());
         return PLDM_ERROR;
     }
     ifs.seekg(0);
@@ -490,7 +498,7 @@
     constexpr auto magicNumber = 0x0222;
     if (htons(header.magicNumber) != magicNumber)
     {
-        std::cerr << "Invalid magic number: " << filePath << "\n";
+        error("Invalid magic number: {DIR_PATH}", "DIR_PATH", filePath.c_str());
         ifs.close();
         return PLDM_ERROR;
     }
@@ -543,8 +551,7 @@
                                  "-no-recovery");
             if (rc < 0)
             {
-                std::cerr << "Error occurred during the mksqusquashfs call"
-                          << std::endl;
+                error("Error occurred during the mksqusquashfs call");
                 setCodeUpdateProgress(false);
                 auto sensorId = getFirmwareUpdateSensor();
                 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
@@ -581,9 +588,7 @@
                             updateDirPath);
             if (rc < 0)
             {
-                std::cerr
-                    << "Error occurred during the generation of the tarball"
-                    << std::endl;
+                error("Error occurred during the generation of the tarball");
                 setCodeUpdateProgress(false);
                 auto sensorId = getFirmwareUpdateSensor();
                 sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
@@ -606,8 +611,7 @@
         }
         else if (nextPid < 0)
         {
-            std::cerr << "Error occurred during fork. ERROR=" << errno
-                      << std::endl;
+            error("Error occurred during fork. ERROR={ERR}", "ERR", errno);
             exit(EXIT_FAILURE);
         }
 
@@ -620,21 +624,21 @@
         int status;
         if (waitpid(pid, &status, 0) < 0)
         {
-            std::cerr << "Error occurred during waitpid. ERROR=" << errno
-                      << std::endl;
+            error("Error occurred during waitpid. ERROR={ERR}", "ERR", errno);
+
             return PLDM_ERROR;
         }
         else if (WEXITSTATUS(status) != 0)
         {
-            std::cerr
-                << "Failed to execute the assembling of the image. STATUS="
-                << status << std::endl;
+            error(
+                "Failed to execute the assembling of the image. STATUS={IMG_STATUS}",
+                "IMG_STATUS", status);
             return PLDM_ERROR;
         }
     }
     else
     {
-        std::cerr << "Error occurred during fork. ERROR=" << errno << std::endl;
+        error("Error occurred during fork. ERROR={ERR}", "ERR", errno);
         return PLDM_ERROR;
     }
 
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index 081a92e..d171173 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -8,6 +8,10 @@
 #include <libpldm/entity_oem_ibm.h>
 #include <libpldm/pldm.h>
 
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
 using namespace pldm::pdr;
 using namespace pldm::utils;
 
@@ -163,8 +167,9 @@
         reinterpret_cast<pldm_state_effecter_pdr*>(entry.data());
     if (!pdr)
     {
-        std::cerr << "Failed to get record by PDR type, ERROR:"
-                  << PLDM_PLATFORM_INVALID_EFFECTER_ID << std::endl;
+        error("Failed to get record by PDR type, ERROR:{ERR_CODE}", "ERR_CODE",
+              lg2::hex,
+              static_cast<unsigned>(PLDM_PLATFORM_INVALID_EFFECTER_ID));
         return;
     }
     pdr->hdr.record_handle = 0;
@@ -214,8 +219,8 @@
         reinterpret_cast<pldm_state_sensor_pdr*>(entry.data());
     if (!pdr)
     {
-        std::cerr << "Failed to get record by PDR type, ERROR:"
-                  << PLDM_PLATFORM_INVALID_SENSOR_ID << std::endl;
+        error("Failed to get record by PDR type, ERROR:{ERR_CODE}", "ERR_CODE",
+              lg2::hex, static_cast<unsigned>(PLDM_PLATFORM_INVALID_SENSOR_ID));
         return;
     }
     pdr->hdr.record_handle = 0;
@@ -307,27 +312,27 @@
         }
         std::cout << tempStream.str() << std::endl;
     }
-    auto oemPlatformEventMessageResponseHandler =
-        [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) {
-            uint8_t completionCode{};
-            uint8_t status{};
-            auto rc = decode_platform_event_message_resp(
-                response, respMsgLen, &completionCode, &status);
-            if (rc || completionCode)
-            {
-                std::cerr << "Failed to decode_platform_event_message_resp: "
-                          << " for code update event rc=" << rc
-                          << ", cc=" << static_cast<unsigned>(completionCode)
-                          << std::endl;
-            }
-        };
+    auto oemPlatformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
+                                                     const pldm_msg* response,
+                                                     size_t respMsgLen) {
+        uint8_t completionCode{};
+        uint8_t status{};
+        auto rc = decode_platform_event_message_resp(response, respMsgLen,
+                                                     &completionCode, &status);
+        if (rc || completionCode)
+        {
+            error(
+                "Failed to decode_platform_event_message_resp: for code update event rc={RC}, cc={CC}",
+                "RC", rc, "CC", static_cast<unsigned>(completionCode));
+        }
+    };
     auto rc = handler->registerRequest(
         mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
         std::move(requestMsg),
         std::move(oemPlatformEventMessageResponseHandler));
     if (rc)
     {
-        std::cerr << "Failed to send BIOS attribute change event message \n";
+        error("Failed to send BIOS attribute change event message ");
     }
 
     return rc;
@@ -372,16 +377,14 @@
                              instanceId);
     if (rc != PLDM_SUCCESS)
     {
-        std::cerr << "Failed to encode state sensor event, rc = " << rc
-                  << std::endl;
+        error("Failed to encode state sensor event, rc = {RC}", "RC", rc);
         requester.markFree(mctp_eid, instanceId);
         return;
     }
     rc = sendEventToHost(requestMsg, instanceId);
     if (rc != PLDM_SUCCESS)
     {
-        std::cerr << "Failed to send event to host: "
-                  << "rc=" << rc << std::endl;
+        error("Failed to send event to host: rc={RC}", "RC", rc);
     }
     return;
 }
@@ -409,7 +412,7 @@
     auto rc = codeUpdate->setRequestedApplyTime();
     if (rc != PLDM_SUCCESS)
     {
-        std::cerr << "setRequestedApplyTime failed \n";
+        error("setRequestedApplyTime failed");
         state = CodeUpdateState::FAIL;
     }
     auto sensorId = codeUpdate->getFirmwareUpdateSensor();
@@ -431,9 +434,9 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Chassis State transition to Off failed,"
-                  << "unable to set property RequestedPowerTransition"
-                  << "ERROR=" << e.what() << "\n";
+        error(
+            "Chassis State transition to Off failed, unable to set property RequestedPowerTransition ERROR={ERR_EXCEP}",
+            "ERR_EXCEP", e.what());
     }
 
     using namespace sdbusplus::bus::match::rules;
@@ -466,9 +469,9 @@
                     }
                     catch (const std::exception& e)
                     {
-                        std::cerr << "Setting one-time restore policy failed,"
-                                  << "unable to set property PowerRestorePolicy"
-                                  << "ERROR=" << e.what() << "\n";
+                        error(
+                            "Setting one-time restore policy failed, unable to set property PowerRestorePolicy ERROR={ERR_EXCEP}",
+                            "ERR_EXCEP", e.what());
                     }
                     dbusMapping = pldm::utils::DBusMapping{
                         "/xyz/openbmc_project/state/bmc0",
@@ -481,10 +484,9 @@
                     }
                     catch (const std::exception& e)
                     {
-                        std::cerr << "BMC state transition to reboot failed,"
-                                  << "unable to set property "
-                                     "RequestedBMCTransition"
-                                  << "ERROR=" << e.what() << "\n";
+                        error(
+                            "BMC state transition to reboot failed, unable to set property RequestedBMCTransition ERROR={ERR_EXCEP}",
+                            "ERR_EXCEP", e.what());
                     }
                 }
             }
@@ -546,8 +548,8 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Failed To reset watchdog timer"
-                  << "ERROR=" << e.what() << std::endl;
+        error("Failed To reset watchdog timer ERROR={ERR_EXCEP}", "ERR_EXCEP",
+              e.what());
         return;
     }
 }
@@ -570,8 +572,8 @@
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Failed To disable watchdog timer"
-                  << "ERROR=" << e.what() << "\n";
+        error("Failed To disable watchdog timer ERROR={ERR_EXCEP}", "ERR_EXCEP",
+              e.what());
     }
 }
 int pldm::responder::oem_ibm_platform::Handler::checkBMCState()
@@ -586,14 +588,13 @@
         if (std::get<std::string>(propertyValue) ==
             "xyz.openbmc_project.State.BMC.BMCState.NotReady")
         {
-            std::cerr << "GetPDR : PLDM stack is not ready for PDR exchange"
-                      << std::endl;
+            error("GetPDR : PLDM stack is not ready for PDR exchange");
             return PLDM_ERROR_NOT_READY;
         }
     }
     catch (const std::exception& e)
     {
-        std::cerr << "Error getting the current BMC state" << std::endl;
+        error("Error getting the current BMC state");
         return PLDM_ERROR;
     }
     return PLDM_SUCCESS;
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index 690d65f..6432cbe 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -6,10 +6,13 @@
 #include <libpldm/platform_oem_ibm.h>
 #include <libpldm/pldm.h>
 
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 #include <iostream>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
@@ -55,8 +58,9 @@
     }
     catch (const sdbusplus::exception_t& e)
     {
-        std::cerr << "Error in getting current host state, " << e.name()
-                  << " Continue sending the bios attribute update event ... \n";
+        error(
+            "Error in getting current host state, {EXCEP_NAME} Continue sending the bios attribute update event ...",
+            "EXCEP_NAME", e.name());
     }
 
     auto instanceId = requester->getInstanceId(eid);
@@ -74,9 +78,9 @@
         requestMsg.size() - sizeof(pldm_msg_hdr), request);
     if (rc != PLDM_SUCCESS)
     {
-        std::cerr
-            << "BIOS Attribute update event message encode failure. PLDM error code = "
-            << std::hex << std::showbase << rc << "\n";
+        error(
+            "BIOS Attribute update event message encode failure. PLDM error code = {RC}",
+            "RC", lg2::hex, rc);
         requester->markFree(eid, instanceId);
         return rc;
     }
@@ -86,8 +90,7 @@
                                                   size_t respMsgLen) {
         if (response == nullptr || !respMsgLen)
         {
-            std::cerr
-                << "Failed to receive response for BIOS Attribute update platform event message \n";
+            error("Failed to receive response for platform event message");
             return;
         }
         uint8_t completionCode{};
@@ -96,11 +99,9 @@
                                                      &completionCode, &status);
         if (rc || completionCode)
         {
-            std::cerr
-                << "Failed to decode BIOS Attribute update platform_event_message_resp: "
-                << "rc=" << rc
-                << ", cc=" << static_cast<unsigned>(completionCode)
-                << std::endl;
+            error(
+                "Failed to decode BIOS Attribute update platform_event_message_resp: rc = {RC}, cc= {CC}",
+                "RC", rc, "CC", static_cast<unsigned>(completionCode));
         }
     };
     rc = handler->registerRequest(
@@ -108,8 +109,8 @@
         std::move(requestMsg), std::move(platformEventMessageResponseHandler));
     if (rc)
     {
-        std::cerr
-            << "Failed to send BIOS Attribute update the platform event message \n";
+        error(
+            "Failed to send BIOS Attribute update the platform event message");
     }
 
     return rc;
diff --git a/oem/ibm/libpldmresponder/utils.cpp b/oem/ibm/libpldmresponder/utils.cpp
index 15987ff..c41211e 100644
--- a/oem/ibm/libpldmresponder/utils.cpp
+++ b/oem/ibm/libpldmresponder/utils.cpp
@@ -6,8 +6,12 @@
 #include <sys/un.h>
 #include <unistd.h>
 
+#include <phosphor-logging/lg2.hpp>
+
 #include <iostream>
 
+PHOSPHOR_LOG2_USING;
+
 namespace pldm
 {
 namespace responder
@@ -23,7 +27,7 @@
     if (strnlen(socketInterface.c_str(), sizeof(addr.sun_path)) ==
         sizeof(addr.sun_path))
     {
-        std::cerr << "setupUnixSocket: UNIX socket path too long" << std::endl;
+        error("setupUnixSocket: UNIX socket path too long");
         return -1;
     }
 
@@ -31,21 +35,21 @@
 
     if ((sock = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1)
     {
-        std::cerr << "setupUnixSocket: socket() call failed" << std::endl;
+        error("setupUnixSocket: socket() call failed");
         return -1;
     }
 
     if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1)
     {
-        std::cerr << "setupUnixSocket: bind() call failed with errno " << errno
-                  << std::endl;
+        error("setupUnixSocket: bind() call failed  with errno {ERR}", "ERR",
+              errno);
         close(sock);
         return -1;
     }
 
     if (listen(sock, 1) == -1)
     {
-        std::cerr << "setupUnixSocket: listen() call failed" << std::endl;
+        error("setupUnixSocket: listen() call failed");
         close(sock);
         return -1;
     }
@@ -63,8 +67,7 @@
     int retval = select(nfd, &rfd, NULL, NULL, &tv);
     if (retval < 0)
     {
-        std::cerr << "setupUnixSocket: select call failed " << errno
-                  << std::endl;
+        error("setupUnixSocket: select call failed {ERR}", "ERR", errno);
         close(sock);
         return -1;
     }
@@ -74,8 +77,7 @@
         fd = accept(sock, NULL, NULL);
         if (fd < 0)
         {
-            std::cerr << "setupUnixSocket: accept() call failed " << errno
-                      << std::endl;
+            error("setupUnixSocket: accept() call failed {ERR}", "ERR", errno);
             close(sock);
             return -1;
         }
@@ -103,8 +105,7 @@
         int retval = select(nfd, NULL, &wfd, NULL, &tv);
         if (retval < 0)
         {
-            std::cerr << "writeToUnixSocket: select call failed " << errno
-                      << std::endl;
+            error("writeToUnixSocket: select call failed {ERR}", "ERR", errno);
             close(sock);
             return -1;
         }
@@ -120,13 +121,12 @@
             {
                 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
                 {
-                    std::cerr << "writeToUnixSocket: Write call failed with "
-                                 "EAGAIN or EWOULDBLOCK or EINTR"
-                              << std::endl;
+                    error(
+                        "writeToUnixSocket: Write call failed with EAGAIN or EWOULDBLOCK or EINTR");
                     nwrite = 0;
                     continue;
                 }
-                std::cerr << "writeToUnixSocket: Failed to write" << std::endl;
+                error("writeToUnixSocket: Failed to write {ERR}", "ERR", errno);
                 close(sock);
                 return -1;
             }