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/libpldmresponder/platform_state_sensor.hpp b/libpldmresponder/platform_state_sensor.hpp
index 25ca51e..d7d6559 100644
--- a/libpldmresponder/platform_state_sensor.hpp
+++ b/libpldmresponder/platform_state_sensor.hpp
@@ -10,16 +10,19 @@
#include <libpldm/platform.h>
#include <libpldm/states.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <cstdint>
#include <map>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
{
namespace platform_state_sensor
{
-
/** @brief Function to get the sensor state
*
* @tparam[in] DBusInterface - DBus interface type
@@ -52,9 +55,10 @@
}
catch (const std::exception& e)
{
- std::cerr << "Get StateSensor EventState from dbus Error, interface : "
- << dbusMapping.objectPath.c_str()
- << " ,exception : " << e.what() << '\n';
+ error(
+ "Get StateSensor EventState from dbus Error, interface : {DBUS_OBJ_PATH}, exception : {ERR_EXCEP}",
+ "DBUS_OBJ_PATH", dbusMapping.objectPath.c_str(), "ERR_EXCEP",
+ e.what());
}
return PLDM_SENSOR_UNKNOWN;
@@ -93,7 +97,7 @@
getRepoByType(handler.getRepo(), stateSensorPDRs, PLDM_STATE_SENSOR_PDR);
if (stateSensorPDRs.empty())
{
- std::cerr << "Failed to get record by PDR type\n";
+ error("Failed to get record by PDR type");
return PLDM_PLATFORM_INVALID_SENSOR_ID;
}
@@ -113,9 +117,9 @@
compSensorCnt = pdr->composite_sensor_count;
if (sensorRearmCnt > compSensorCnt)
{
- std::cerr << "The requester sent wrong sensorRearm"
- << " count for the sensor, SENSOR_ID=" << sensorId
- << "SENSOR_REARM_COUNT=" << sensorRearmCnt << "\n";
+ error(
+ "The requester sent wrong sensorRearm count for the sensor, SENSOR_ID={SENSOR_ID} SENSOR_REARM_COUNT={SENSOR_REARM_CNT}",
+ "SENSOR_ID", sensorId, "SENSOR_REARM_CNT", sensorRearmCnt);
return PLDM_PLATFORM_REARM_UNAVAILABLE_IN_PRESENT_STATE;
}
@@ -159,8 +163,8 @@
}
catch (const std::out_of_range& e)
{
- std::cerr << "the sensorId does not exist. sensor id: " << sensorId
- << e.what() << '\n';
+ error("the sensorId does not exist. sensor id: {SENSOR_ID} {ERR_EXCEP}",
+ "SENSOR_ID", sensorId, "ERR_EXCEP", e.what());
rc = PLDM_ERROR;
}