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/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;
}