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_numeric_effecter.hpp b/libpldmresponder/platform_numeric_effecter.hpp
index 37d5c00..b01d6b0 100644
--- a/libpldmresponder/platform_numeric_effecter.hpp
+++ b/libpldmresponder/platform_numeric_effecter.hpp
@@ -12,16 +12,19 @@
#include <math.h>
#include <stdint.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <map>
#include <optional>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
{
namespace platform_numeric_effecter
{
-
/** @brief Function to get the effecter value by PDR factor coefficient, etc.
* @param[in] pdr - The structure of pldm_numeric_effecter_value_pdr.
* @param[in] effecterValue - effecter value.
@@ -222,7 +225,7 @@
}
else
{
- std::cerr << "Wrong field effecterDataSize...\n";
+ error("Wrong field effecterDataSize...");
return {PLDM_ERROR, {}};
}
}
@@ -261,7 +264,7 @@
PLDM_NUMERIC_EFFECTER_PDR);
if (numericEffecterPDRs.empty())
{
- std::cerr << "The Numeric Effecter PDR repo is empty." << std::endl;
+ error("The Numeric Effecter PDR repo is empty.");
return PLDM_ERROR;
}
@@ -289,7 +292,7 @@
if (effecterValueLength != effecterValueArrayLength)
{
- std::cerr << "effecter data size is incorrect.\n";
+ error("effecter data size is incorrect.");
return PLDM_ERROR_INVALID_DATA;
}
@@ -314,16 +317,18 @@
}
catch (const std::exception& e)
{
- std::cerr << "Error setting property, ERROR=" << e.what()
- << " PROPERTY=" << dbusMapping.propertyName
- << " INTERFACE=" << dbusMapping.interface << " PATH="
- << dbusMapping.objectPath << "\n";
+ error(
+ "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
+ "ERR_EXCEP", e.what(), "DBUS_PROP", dbusMapping.propertyName,
+ "DBUS_INTF", dbusMapping.interface, "DBUS_OBJ_PATH",
+ dbusMapping.objectPath.c_str());
return PLDM_ERROR;
}
}
catch (const std::out_of_range& e)
{
- std::cerr << "Unknown effecter ID : " << effecterId << e.what() << '\n';
+ error("Unknown effecter ID : {EFFECTER_ID} {ERR_EXCEP}", "EFFECTER_ID",
+ effecterId, "ERR_EXCEP", e.what());
return PLDM_ERROR;
}