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/base.cpp b/libpldmresponder/base.cpp
index e5030ec..4639007 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -11,6 +11,8 @@
#include <libpldm/platform.h>
#include <libpldm/pldm.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <array>
#include <cstring>
#include <iostream>
@@ -23,6 +25,8 @@
#include <libpldm/host.h>
#endif
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
using Type = uint8_t;
@@ -193,8 +197,8 @@
if (rc != PLDM_SUCCESS)
{
requester.markFree(eid, instanceId);
- std::cerr << "Failed to encode_set_event_receiver_req, rc = "
- << std::hex << std::showbase << rc << std::endl;
+ error("Failed to encode_set_event_receiver_req, rc = {RC}", "RC",
+ lg2::hex, rc);
return;
}
@@ -203,8 +207,7 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr << "Failed to receive response for "
- "setEventReceiver command \n";
+ error("Failed to receive response for setEventReceiver command");
return;
}
@@ -213,9 +216,9 @@
&completionCode);
if (rc || completionCode)
{
- std::cerr << "Failed to decode setEventReceiver command response,"
- << " rc=" << rc << "cc=" << (unsigned)completionCode
- << "\n";
+ error(
+ "Failed to decode setEventReceiver command response, rc = {RC}, cc = {CC}",
+ "RC", rc, "CC", (unsigned)completionCode);
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
}
@@ -226,8 +229,7 @@
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Failed to send the setEventReceiver request"
- << "\n";
+ error("Failed to send the setEventReceiver request");
}
if (oemPlatformHandler)
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 39aad5b..a75e9d6 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -4,6 +4,8 @@
#include <time.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <array>
#include <chrono>
#include <ctime>
@@ -13,6 +15,8 @@
#include <variant>
#include <vector>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::utils;
namespace pldm
@@ -123,8 +127,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "Error getting time, PATH=" << bmcTimePath
- << " TIME INTERACE=" << timeInterface << "\n";
+ error(
+ "Error getting time, PATH={BMC_TIME_PATH} TIME INTERACE={TIME_INTERFACE}",
+ "BMC_TIME_PATH", bmcTimePath, "TIME_INTERFACE", timeInterface);
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
}
@@ -177,10 +182,10 @@
}
catch (const std::exception& e)
{
- std::cerr << "Error getting the time sync property, PATH="
- << timeSyncPath << "INTERFACE=" << timeSyncInterface
- << "PROPERTY=" << timeSyncProperty << "ERROR=" << e.what()
- << "\n";
+ error(
+ "Error getting the time sync property, PATH={TIME_SYNC_PATH} INTERFACE={SYNC_INTERFACE} PROPERTY={SYNC_PROP} ERROR={ERR_EXCEP}",
+ "TIME_SYNC_PATH", timeSyncPath, "SYNC_INTERFACE", timeSyncInterface,
+ "SYNC_PROP", timeSyncProperty, "ERR_EXCEP", e.what());
}
constexpr auto setTimeInterface = "xyz.openbmc_project.Time.EpochTime";
@@ -207,10 +212,10 @@
}
catch (const std::exception& e)
{
- std::cerr << "Error Setting time,PATH=" << setTimePath
- << "TIME INTERFACE=" << setTimeInterface
- << "ERROR=" << e.what() << "\n";
-
+ error(
+ "Error Setting time,PATH={SET_TIME_PATH} TIME INTERFACE={TIME_INTERFACE} ERROR={ERR_EXCEP}",
+ "SET_TIME_PATH", setTimePath, "TIME_INTERFACE", setTimeInterface,
+ "ERR_EXCEP", e.what());
return ccOnlyResponse(request, PLDM_ERROR);
}
diff --git a/libpldmresponder/bios_config.cpp b/libpldmresponder/bios_config.cpp
index b9eeb79..92a0d04 100644
--- a/libpldmresponder/bios_config.cpp
+++ b/libpldmresponder/bios_config.cpp
@@ -6,6 +6,7 @@
#include "bios_table.hpp"
#include "common/bios_utils.hpp"
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
#include <fstream>
@@ -15,6 +16,8 @@
#include "oem/ibm/libpldmresponder/platform_oem_ibm.hpp"
#endif
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::dbus_api;
using namespace pldm::utils;
@@ -450,8 +453,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "failed to update BaseBIOSTable property, ERROR="
- << e.what() << "\n";
+ error("failed to update BaseBIOSTable property, ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
}
@@ -499,8 +502,8 @@
// bios-settings-manager in sync
catch (const std::exception& e)
{
- std::cerr << "Failed to read BaseBIOSTable property, ERROR=" << e.what()
- << "\n";
+ error("Failed to read BaseBIOSTable property, ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
Table attrTable, attrValueTable;
@@ -525,8 +528,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Construct Table Entry Error, AttributeName = "
- << attr->name << std::endl;
+ error("Construct Table Entry Error, AttributeName = {ATTR_NAME}",
+ "ATTR_NAME", attr->name);
}
}
@@ -608,16 +611,16 @@
}
catch (const std::exception& e)
{
- std::cerr
- << "Failed to parse JSON config file(entry handler) : "
- << filePath.c_str() << ", " << e.what() << std::endl;
+ error(
+ "Failed to parse JSON config file(entry handler) : {JSON_PATH}, {ERR_EXCEP}",
+ "JSON_PATH", filePath.c_str(), "ERR_EXCEP", e.what());
}
}
}
catch (const std::exception& e)
{
- std::cerr << "Failed to parse JSON config file : "
- << filePath.c_str() << std::endl;
+ error("Failed to parse JSON config file : {JSON_PATH}", "JSON_PATH",
+ filePath.c_str());
}
}
}
@@ -682,10 +685,12 @@
for (uint8_t handle : handles)
{
- std::cout << "BIOS:" << attrName << ", updated to value: "
- << displayStringHandle(attrHandle, handle, attrTable,
- stringTable)
- << ", by BMC: " << std::boolalpha << isBMC << "\n";
+ auto nwVal = displayStringHandle(attrHandle, handle, attrTable,
+ stringTable);
+ auto chkBMC = isBMC ? "true" : "false";
+ info(
+ "BIOS:{ATTR_NAME}, updated to value: {NEW_VAL}, by BMC: {CHK_BMC} ",
+ "ATTR_NAME", attrName, "NEW_VAL", nwVal, "CHK_BMC", chkBMC);
}
break;
}
@@ -694,8 +699,10 @@
{
auto value =
table::attribute_value::decodeIntegerEntry(attrValueEntry);
- std::cout << "BIOS:" << attrName << ", updated to value: " << value
- << ", by BMC:" << std::boolalpha << isBMC << std::endl;
+ auto chkBMC = isBMC ? "true" : "false";
+ info(
+ "BIOS: {ATTR_NAME}, updated to value: {UPDATED_VAL}, by BMC: {CHK_BMC}",
+ "ATTR_NAME", attrName, "UPDATED_VAL", value, "CHK_BMC", chkBMC);
break;
}
case PLDM_BIOS_STRING:
@@ -703,8 +710,10 @@
{
auto value =
table::attribute_value::decodeStringEntry(attrValueEntry);
- std::cout << "BIOS:" << attrName << " updated to value: " << value
- << ", by BMC:" << std::boolalpha << isBMC << std::endl;
+ auto chkBMC = isBMC ? "true" : "false";
+ info(
+ "BIOS: {ATTR_NAME}, updated to value: {UPDATED_VAL}, by BMC: {CHK_BMC}",
+ "ATTR_NAME", attrName, "UPDATED_VAL", value, "CHK_BMC", chkBMC);
break;
}
default:
@@ -735,8 +744,8 @@
}
if (value[0] >= pvHdls.size())
{
- std::cerr << "Enum: Illgeal index, Index = " << (int)value[0]
- << std::endl;
+ error("Enum: Illgeal index, Index = {ATTR_INDEX}", "ATTR_INDEX",
+ (int)value[0]);
return PLDM_ERROR_INVALID_DATA;
}
return PLDM_SUCCESS;
@@ -751,8 +760,8 @@
if (value < lower || value > upper)
{
- std::cerr << "Integer: out of bound, value = " << value
- << std::endl;
+ error("Integer: out of bound, value = {ATTR_VALUE}",
+ "ATTR_VALUE", value);
return PLDM_ERROR_INVALID_DATA;
}
return PLDM_SUCCESS;
@@ -766,15 +775,16 @@
if (value.size() < stringConf.minLength ||
value.size() > stringConf.maxLength)
{
- std::cerr << "String: Length error, string = " << value
- << " length = " << value.size() << std::endl;
+ error(
+ "String: Length error, string = {ATTR_VALUE} length {LEN}",
+ "ATTR_VALUE", value, "LEN", value.size());
return PLDM_ERROR_INVALID_LENGTH;
}
return PLDM_SUCCESS;
}
default:
- std::cerr << "ReadOnly or Unspported type, type = " << attrType
- << std::endl;
+ error("ReadOnly or Unspported type, type = {ATTR_TYPE}",
+ "ATTR_TYPE", attrType);
return PLDM_ERROR;
};
}
@@ -838,7 +848,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "Set attribute value error: " << e.what() << std::endl;
+ error("Set attribute value error: {ERR_EXCEP}", "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
@@ -859,7 +869,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "Remove the tables error: " << e.what() << std::endl;
+ error("Remove the tables error: {ERR_EXCEP}", "ERR_EXCEP", e.what());
}
}
@@ -880,7 +890,7 @@
auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
if (!stringTable.has_value())
{
- std::cerr << "BIOS string table unavailable\n";
+ error("BIOS string table unavailable");
return;
}
BIOSStringTable biosStringTable(*stringTable);
@@ -891,23 +901,24 @@
}
catch (const std::invalid_argument& e)
{
- std::cerr << "Could not find handle for BIOS string, ATTRIBUTE="
- << attrName.c_str() << "\n";
+ error("Could not find handle for BIOS string, ATTRIBUTE={ATTR_NAME}",
+ "ATTR_NAME", attrName.c_str());
return;
}
auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE);
if (!attrTable.has_value())
{
- std::cerr << "Attribute table not present\n";
+ error("Attribute table not present");
return;
}
const struct pldm_bios_attr_table_entry* tableEntry =
table::attribute::findByStringHandle(*attrTable, attrNameHdl);
if (tableEntry == nullptr)
{
- std::cerr << "Attribute not found in attribute table, name= "
- << attrName.c_str() << "name handle=" << attrNameHdl << "\n";
+ error(
+ "Attribute not found in attribute table, name= {ATTR_NAME} name handle={ATTR_HANDLE}",
+ "ATTR_NAME", attrName.c_str(), "ATTR_HANDLE", attrNameHdl);
return;
}
@@ -918,7 +929,7 @@
if (!attrValueSrcTable.has_value())
{
- std::cerr << "Attribute value table not present\n";
+ error("Attribute value table not present");
return;
}
@@ -927,9 +938,9 @@
newValue, attrHdl, attrType, newPropVal);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Could not update the attribute value table for attribute "
- "handle="
- << attrHdl << " and type=" << (uint32_t)attrType << "\n";
+ error(
+ "Could not update the attribute value table for attribute handle={ATTR_HANDLE} and type={ATTR_TYPE}",
+ "ATTR_HANDLE", attrHdl, "ATTR_TYPE", (uint32_t)attrType);
return;
}
auto destTable = table::attribute_value::updateTable(
@@ -942,8 +953,8 @@
rc = setAttrValue(newValue.data(), newValue.size(), true, false);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "could not setAttrValue on base bios table and dbus, rc = "
- << rc << "\n";
+ error("could not setAttrValue on base bios table and dbus, rc = {RC}",
+ "RC", rc);
}
}
@@ -987,8 +998,8 @@
if (iter == biosAttributes.end())
{
- std::cerr << "Wrong attribute name, attributeName = "
- << attributeName << std::endl;
+ error("Wrong attribute name, attributeName = {ATTR_NAME}",
+ "ATTR_NAME", attributeName);
continue;
}
@@ -1004,8 +1015,8 @@
type != BIOSConfigManager::AttributeType::String &&
type != BIOSConfigManager::AttributeType::Integer)
{
- std::cerr << "Attribute type not supported, attributeType = "
- << attributeType << std::endl;
+ error("Attribute type not supported, attributeType = {ATTR_TYPE}",
+ "ATTR_TYPE", attributeType);
continue;
}
diff --git a/libpldmresponder/bios_config.hpp b/libpldmresponder/bios_config.hpp
index 4d0638a..4e69089 100644
--- a/libpldmresponder/bios_config.hpp
+++ b/libpldmresponder/bios_config.hpp
@@ -8,6 +8,7 @@
#include <libpldm/bios_table.h>
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <functional>
#include <iostream>
@@ -17,6 +18,8 @@
#include <string>
#include <vector>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
@@ -224,8 +227,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Constructs Attribute Error, " << e.what()
- << std::endl;
+ error("Constructs Attribute Error, {ERR_EXCEP}", "ERR_EXCEP",
+ e.what());
}
}
diff --git a/libpldmresponder/bios_enum_attribute.cpp b/libpldmresponder/bios_enum_attribute.cpp
index e878827..7197553 100644
--- a/libpldmresponder/bios_enum_attribute.cpp
+++ b/libpldmresponder/bios_enum_attribute.cpp
@@ -4,8 +4,12 @@
#include "common/utils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::utils;
namespace pldm
@@ -113,8 +117,8 @@
}
else
{
- std::cerr << "Unknown D-Bus property type, TYPE="
- << dBusMap->propertyType << "\n";
+ error("Unknown D-Bus property type, TYPE={PROP_TYPE}", "PROP_TYPE",
+ dBusMap->propertyType);
throw std::invalid_argument("Unknown D-BUS property type");
}
valMap.emplace(value, possibleValues[pos]);
@@ -238,8 +242,8 @@
auto iter = valMap.find(newPropVal);
if (iter == valMap.end())
{
- std::cerr << "Could not find index for new BIOS enum, value="
- << std::get<std::string>(newPropVal) << "\n";
+ error("Could not find index for new BIOS enum, value={PROP_VAL}",
+ "PROP_VAL", std::get<std::string>(newPropVal));
return PLDM_ERROR;
}
auto currentValue = iter->second;
diff --git a/libpldmresponder/bios_integer_attribute.cpp b/libpldmresponder/bios_integer_attribute.cpp
index 29d309a..bf5c7a6 100644
--- a/libpldmresponder/bios_integer_attribute.cpp
+++ b/libpldmresponder/bios_integer_attribute.cpp
@@ -2,6 +2,10 @@
#include "common/utils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::utils;
namespace pldm
@@ -10,7 +14,6 @@
{
namespace bios
{
-
BIOSIntegerAttribute::BIOSIntegerAttribute(const Json& entry,
DBusHandler* const dbusHandler) :
BIOSAttribute(entry, dbusHandler)
@@ -33,13 +36,12 @@
auto rc = pldm_bios_table_attr_entry_integer_info_check(&info, &errmsg);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Wrong filed for integer attribute, ATTRIBUTE_NAME="
- << attr.c_str() << " ERRMSG=" << errmsg
- << " LOWER_BOUND=" << integerInfo.lowerBound
- << " UPPER_BOUND=" << integerInfo.upperBound
- << " DEFAULT_VALUE=" << integerInfo.defaultValue
- << " SCALAR_INCREMENT=" << integerInfo.scalarIncrement
- << "\n";
+ error(
+ "Wrong filed for integer attribute, ATTRIBUTE_NAME={ATTR_NAME} ERRMSG= {ERR_MSG} LOWER_BOUND={LOW_BOUND} UPPER_BOUND={UPPER_BOUND} DEFAULT_VALUE={DEF_VAL} SCALAR_INCREMENT={SCALAR_INCREMENT}",
+ "ATTR_NAME", attr.c_str(), "ERR_MSG", errmsg, "LOW_BOUND",
+ integerInfo.lowerBound, "UPPER_BOUND", integerInfo.upperBound,
+ "DEF_VAL", integerInfo.defaultValue, "SCALAR_INCREMENT",
+ integerInfo.scalarIncrement);
throw std::invalid_argument("Wrong field for integer attribute");
}
}
@@ -95,8 +97,8 @@
static_cast<double>(currentValue));
}
- std::cerr << "Unsupported property type on dbus: " << dBusMap->propertyType
- << std::endl;
+ error("Unsupported property type on dbus: {DBUS_PROP}", "DBUS_PROP",
+ dBusMap->propertyType);
throw std::invalid_argument("dbus type error");
}
@@ -175,8 +177,8 @@
}
else
{
- std::cerr << "Unsupported property type for getAttrValue: "
- << dBusMap->propertyType << std::endl;
+ error("Unsupported property type for getAttrValue: {DBUS_PROP}",
+ "DBUS_PROP", dBusMap->propertyType);
throw std::invalid_argument("dbus type error");
}
return value;
@@ -199,8 +201,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Get Integer Attribute Value Error: AttributeName = "
- << name << std::endl;
+ error("Get Integer Attribute Value Error: AttributeName = {ATTR_NAME}",
+ "ATTR_NAME", name);
return integerInfo.defaultValue;
}
}
diff --git a/libpldmresponder/bios_string_attribute.cpp b/libpldmresponder/bios_string_attribute.cpp
index d89ab49..273cf48 100644
--- a/libpldmresponder/bios_string_attribute.cpp
+++ b/libpldmresponder/bios_string_attribute.cpp
@@ -2,10 +2,14 @@
#include "common/utils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <iostream>
#include <tuple>
#include <variant>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::utils;
namespace pldm
@@ -14,7 +18,6 @@
{
namespace bios
{
-
BIOSStringAttribute::BIOSStringAttribute(const Json& entry,
DBusHandler* const dbusHandler) :
BIOSAttribute(entry, dbusHandler)
@@ -23,8 +26,9 @@
auto iter = strTypeMap.find(strTypeTmp);
if (iter == strTypeMap.end())
{
- std::cerr << "Wrong string type, STRING_TYPE=" << strTypeTmp
- << " ATTRIBUTE_NAME=" << name << "\n";
+ error(
+ "Wrong string type, STRING_TYPE={STR_TYPE} ATTRIBUTE_NAME={ATTR_NAME}",
+ "STR_TYP", strTypeTmp, "ATTR_NAME", name);
throw std::invalid_argument("Wrong string type");
}
stringInfo.stringType = static_cast<uint8_t>(iter->second);
@@ -48,12 +52,11 @@
auto rc = pldm_bios_table_attr_entry_string_info_check(&info, &errmsg);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Wrong field for string attribute, ATTRIBUTE_NAME=" << name
- << " ERRMSG=" << errmsg
- << " MINIMUM_STRING_LENGTH=" << stringInfo.minLength
- << " MAXIMUM_STRING_LENGTH=" << stringInfo.maxLength
- << " DEFAULT_STRING_LENGTH=" << stringInfo.defLength
- << " DEFAULT_STRING=" << stringInfo.defString << "\n";
+ error(
+ "Wrong field for string attribute, ATTRIBUTE_NAME={ATTR_NAME} ERRMSG={ERR_MSG} MINIMUM_STRING_LENGTH={MIN_LEN} MAXIMUM_STRING_LENGTH={MAX_LEN} DEFAULT_STRING_LENGTH={DEF_LEN} DEFAULT_STRING={DEF_STR}",
+ "ATTR_NAME", name, "ERR_MSG", errmsg, "MIN_LEN",
+ stringInfo.minLength, "MAX_LEN", stringInfo.maxLength, "DEF_LEN",
+ stringInfo.defLength, "DEF_STR", stringInfo.defString);
throw std::invalid_argument("Wrong field for string attribute");
}
}
@@ -86,8 +89,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Get String Attribute Value Error: AttributeName = "
- << name << std::endl;
+ error("Get String Attribute Value Error: AttributeName = {ATTR_NAME}",
+ "ATTR_NAME", name);
return stringInfo.defString;
}
}
@@ -142,8 +145,8 @@
}
catch (const std::bad_variant_access& e)
{
- std::cerr << "invalid value passed for the property, error: "
- << e.what() << "\n";
+ error("invalid value passed for the property, error: {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
return PLDM_SUCCESS;
diff --git a/libpldmresponder/event_parser.cpp b/libpldmresponder/event_parser.cpp
index 990ff7c..c88f3f5 100644
--- a/libpldmresponder/event_parser.cpp
+++ b/libpldmresponder/event_parser.cpp
@@ -1,5 +1,6 @@
#include "event_parser.hpp"
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
@@ -7,9 +8,10 @@
#include <iostream>
#include <set>
+PHOSPHOR_LOG2_USING;
+
namespace pldm::responder::events
{
-
namespace fs = std::filesystem;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -27,8 +29,8 @@
fs::path dir(dirPath);
if (!fs::exists(dir) || fs::is_empty(dir))
{
- std::cerr << "Event config directory does not exist or empty, DIR="
- << dirPath << "\n";
+ error("Event config directory does not exist or empty, DIR={DIR_PATH}",
+ "DIR_PATH", dirPath.c_str());
return;
}
@@ -39,8 +41,9 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing Event state sensor JSON file failed, FILE="
- << file.path();
+ error(
+ "Parsing Event state sensor JSON file failed, FILE={FILE_PATH}",
+ "FILE_PATH", file.path().c_str());
continue;
}
@@ -69,11 +72,11 @@
(supportedDbusPropertyTypes.find(dbusInfo.propertyType) ==
supportedDbusPropertyTypes.end()))
{
- std::cerr << "Invalid dbus config,"
- << " OBJPATH=" << dbusInfo.objectPath << " INTERFACE="
- << dbusInfo.interface << " PROPERTY_NAME="
- << dbusInfo.propertyName
- << " PROPERTY_TYPE=" << dbusInfo.propertyType << "\n";
+ error(
+ "Invalid dbus config, OBJPATH= {DBUS_OBJ_PATH} INTERFACE={DBUS_INTF} PROPERTY_NAME={DBUS_PROP} PROPERTY_TYPE={DBUS_PROP_TYPE}",
+ "DBUS_OBJ_PATH", dbusInfo.objectPath.c_str(), "DBUS_INTF",
+ dbusInfo.interface, "DBUS_PROP", dbusInfo.propertyName,
+ "DBUS_PROP_TYPE", dbusInfo.propertyType);
continue;
}
@@ -82,10 +85,10 @@
if ((eventStates.size() == 0) || (propertyValues.size() == 0) ||
(eventStates.size() != propertyValues.size()))
{
- std::cerr << "Invalid event state JSON config,"
- << " EVENT_STATE_SIZE=" << eventStates.size()
- << " PROPERTY_VALUE_SIZE=" << propertyValues.size()
- << "\n";
+ error(
+ "Invalid event state JSON config, EVENT_STATE_SIZE={EVENT_STATE_SIZE} PROPERTY_VALUE_SIZE={PROP_VAL_SIZE}",
+ "EVENT_STATE_SIZE", eventStates.size(), "PROP_VAL_SIZE",
+ propertyValues.size());
continue;
}
@@ -127,8 +130,8 @@
}
catch (const std::out_of_range& e)
{
- std::cerr << "Invalid event state" << static_cast<unsigned>(state)
- << '\n';
+ error("Invalid event state {EVENT_STATE}", "EVENT_STATE",
+ static_cast<unsigned>(state));
return PLDM_ERROR_INVALID_DATA;
}
@@ -138,10 +141,11 @@
}
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;
}
}
@@ -153,4 +157,4 @@
return PLDM_SUCCESS;
}
-} // namespace pldm::responder::events
\ No newline at end of file
+} // namespace pldm::responder::events
diff --git a/libpldmresponder/fru.cpp b/libpldmresponder/fru.cpp
index 419f780..9b0389b 100644
--- a/libpldmresponder/fru.cpp
+++ b/libpldmresponder/fru.cpp
@@ -7,11 +7,14 @@
#include <libpldm/utils.h>
#include <systemd/sd-journal.h>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <iostream>
#include <set>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
@@ -39,8 +42,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Look up of inventory objects failed and PLDM FRU table "
- "creation failed\n";
+ error(
+ "Look up of inventory objects failed and PLDM FRU table creation failed");
return;
}
@@ -103,9 +106,9 @@
}
catch (const std::exception& e)
{
- std::cout << "Config JSONs missing for the item "
- "interface type, interface = "
- << interface.first << "\n";
+ info(
+ "Config JSONs missing for the item interface type, interface = {INTF}",
+ "INTF", interface.first);
break;
}
}
@@ -150,9 +153,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "failed to make a d-bus call "
- "Asociation, ERROR= "
- << e.what() << "\n";
+ error("failed to make a d-bus call Asociation, ERROR= {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return {};
}
return currentBmcVersion;
diff --git a/libpldmresponder/fru_parser.cpp b/libpldmresponder/fru_parser.cpp
index aa85dc8..13f740e 100644
--- a/libpldmresponder/fru_parser.cpp
+++ b/libpldmresponder/fru_parser.cpp
@@ -1,23 +1,23 @@
#include "fru_parser.hpp"
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::responder::dbus;
namespace pldm
{
-
namespace responder
{
-
namespace fru_parser
{
-
using Json = nlohmann::json;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -50,8 +50,9 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing FRU Dbus Lookup Map config file failed, FILE="
- << masterJsonPath;
+ error(
+ "Parsing FRU Dbus Lookup Map config file failed, FILE={JSON_PATH}",
+ "JSON_PATH", masterJsonPath.c_str());
std::abort();
}
std::map<Interface, EntityType> defIntfToEntityType;
@@ -66,7 +67,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "FRU DBus lookup map format error\n";
+ error("FRU DBus lookup map format error");
throw InternalFailure();
}
}
@@ -118,7 +119,8 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing FRU config file failed, FILE=" << file.path();
+ error("Parsing FRU config file failed, FILE={FILE_PATH}",
+ "FILE_PATH", file.path().c_str());
throw InternalFailure();
}
diff --git a/libpldmresponder/meson.build b/libpldmresponder/meson.build
index ed68a84..c1b1b7f 100644
--- a/libpldmresponder/meson.build
+++ b/libpldmresponder/meson.build
@@ -1,5 +1,6 @@
libpldmresponder_deps = [
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
nlohmann_json,
sdbusplus,
sdeventplus,
diff --git a/libpldmresponder/pdr_numeric_effecter.hpp b/libpldmresponder/pdr_numeric_effecter.hpp
index df5faf9..d342636 100644
--- a/libpldmresponder/pdr_numeric_effecter.hpp
+++ b/libpldmresponder/pdr_numeric_effecter.hpp
@@ -4,6 +4,10 @@
#include <libpldm/platform.h>
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
@@ -37,7 +41,7 @@
reinterpret_cast<pldm_numeric_effecter_value_pdr*>(entry.data());
if (!pdr)
{
- std::cerr << "Failed to get numeric effecter PDR.\n";
+ error("Failed to get numeric effecter PDR.");
continue;
}
pdr->hdr.record_handle = 0;
@@ -216,8 +220,9 @@
}
catch (const std::exception& e)
{
- std::cerr << "D-Bus object path does not exist, effecter ID: "
- << pdr->effecter_id << "\n";
+ error(
+ "D-Bus object path does not exist, effecter ID: {EFFECTER_ID}",
+ "EFFECTER_ID", static_cast<uint16_t>(pdr->effecter_id));
}
dbusMappings.emplace_back(std::move(dbusMapping));
diff --git a/libpldmresponder/pdr_state_effecter.hpp b/libpldmresponder/pdr_state_effecter.hpp
index 37a8f06..db76086 100644
--- a/libpldmresponder/pdr_state_effecter.hpp
+++ b/libpldmresponder/pdr_state_effecter.hpp
@@ -6,6 +6,10 @@
#include <config.h>
#include <libpldm/platform.h>
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
@@ -39,10 +43,10 @@
auto statesSize = set.value("size", 0);
if (!statesSize)
{
- std::cerr << "Malformed PDR JSON return "
- "pdrEntry;- no state set "
- "info, TYPE="
- << PLDM_STATE_EFFECTER_PDR << "\n";
+ error(
+ "Malformed PDR JSON return pdrEntry;- no state set info, TYPE={STATE_EFFECTER_PDR}",
+ "STATE_EFFECTER_PDR",
+ static_cast<unsigned>(PLDM_STATE_EFFECTER_PDR));
throw InternalFailure();
}
pdrSize += sizeof(state_effecter_possible_states) -
@@ -57,7 +61,7 @@
reinterpret_cast<pldm_state_effecter_pdr*>(entry.data());
if (!pdr)
{
- std::cerr << "Failed to get state effecter PDR.\n";
+ error("Failed to get state effecter PDR.");
continue;
}
pdr->hdr.record_handle = 0;
@@ -158,8 +162,9 @@
}
catch (const std::exception& e)
{
- std::cerr << "D-Bus object path does not exist, effecter ID: "
- << pdr->effecter_id << "\n";
+ error(
+ "D-Bus object path does not exist, effecter ID: {EFFECTER_ID}",
+ "EFFECTER_ID", static_cast<uint16_t>(pdr->effecter_id));
}
dbusMappings.emplace_back(std::move(dbusMapping));
diff --git a/libpldmresponder/pdr_state_sensor.hpp b/libpldmresponder/pdr_state_sensor.hpp
index 6effc53..838f6e7 100644
--- a/libpldmresponder/pdr_state_sensor.hpp
+++ b/libpldmresponder/pdr_state_sensor.hpp
@@ -4,6 +4,10 @@
#include <libpldm/platform.h>
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
@@ -37,10 +41,10 @@
auto statesSize = set.value("size", 0);
if (!statesSize)
{
- std::cerr << "Malformed PDR JSON return "
- "pdrEntry;- no state set "
- "info, TYPE="
- << PLDM_STATE_SENSOR_PDR << "\n";
+ error(
+ "Malformed PDR JSON return pdrEntry;- no state set info, TYPE={STATE_SENSOR_PDR}",
+ "STATE_SENSOR_PDR",
+ static_cast<int>(PLDM_STATE_SENSOR_PDR));
throw InternalFailure();
}
pdrSize += sizeof(state_sensor_possible_states) -
@@ -55,7 +59,7 @@
reinterpret_cast<pldm_state_sensor_pdr*>(entry.data());
if (!pdr)
{
- std::cerr << "Failed to get state sensor PDR.\n";
+ error("Failed to get state sensor PDR.");
continue;
}
pdr->hdr.record_handle = 0;
@@ -169,8 +173,9 @@
}
catch (const std::exception& e)
{
- std::cerr << "D-Bus object path does not exist, sensor ID: "
- << pdr->sensor_id << "\n";
+ error(
+ "D-Bus object path does not exist, sensor ID: {SENSOR_ID}",
+ "SENSOR_ID", static_cast<uint16_t>(pdr->sensor_id));
}
dbusMappings.emplace_back(std::move(dbusMapping));
diff --git a/libpldmresponder/pdr_utils.cpp b/libpldmresponder/pdr_utils.cpp
index fb7ffd6..89bcba8 100644
--- a/libpldmresponder/pdr_utils.cpp
+++ b/libpldmresponder/pdr_utils.cpp
@@ -3,19 +3,20 @@
#include <config.h>
#include <libpldm/platform.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <climits>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::pdr;
namespace pldm
{
-
namespace responder
{
-
namespace pdr_utils
{
-
pldm_pdr* Repo::getPdr() const
{
return repo;
@@ -80,10 +81,9 @@
StatestoDbusVal valueMap;
if (dBusValues.size() != pv.size())
{
- std::cerr
- << "dBusValues size is not equal to pv size, dBusValues Size: "
- << dBusValues.size() << ", pv Size: " << pv.size() << "\n";
-
+ error(
+ "dBusValues size is not equal to pv size, dBusValues Size: {DBUS_VAL_SIZE}, pv Size: {PV_SIZE}",
+ "DBUS_VAL_SIZE", dBusValues.size(), "PV_SIZE", pv.size());
return {};
}
@@ -131,8 +131,8 @@
}
else
{
- std::cerr << "Unknown D-Bus property type, TYPE=" << type.c_str()
- << "\n";
+ error("Unknown D-Bus property type, TYPE={OTHER_TYPE}",
+ "OTHER_TYPE", type.c_str());
return {};
}
diff --git a/libpldmresponder/pdr_utils.hpp b/libpldmresponder/pdr_utils.hpp
index 44ac008..6c1264a 100644
--- a/libpldmresponder/pdr_utils.hpp
+++ b/libpldmresponder/pdr_utils.hpp
@@ -7,6 +7,7 @@
#include <stdint.h>
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
@@ -15,6 +16,8 @@
#include <iostream>
#include <string>
+PHOSPHOR_LOG2_USING;
+
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -22,13 +25,10 @@
namespace pldm
{
-
namespace responder
{
-
namespace pdr_utils
{
-
/** @struct Type ID associated with pdr
*
*/
@@ -81,7 +81,8 @@
std::ifstream jsonFile(path);
if (!jsonFile.is_open())
{
- std::cerr << "Error opening PDR JSON file, PATH=" << path << "\n";
+ error("Error opening PDR JSON file, PATH={JSON_PATH}", "JSON_PATH",
+ path);
return {};
}
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index fa6058d..c337f2d 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -16,6 +16,10 @@
#include <libpldm/entity.h>
#include <libpldm/state_set.h>
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::utils;
using namespace pldm::responder::pdr;
using namespace pldm::responder::pdr_utils;
@@ -119,21 +123,24 @@
}
catch (const InternalFailure& e)
{
- std::cerr << "PDR config directory does not exist or empty, TYPE= "
- << pdrType << "PATH= " << dirEntry
- << " ERROR=" << e.what() << "\n";
+ error(
+ "PDR config directory does not exist or empty, TYPE= {PDR_TYPE} PATH={DIR_PATH} ERROR={ERR_EXCEP}",
+ "PDR_TYPE", pdrType, "DIR_PATH", dirEntry.path().string(),
+ "ERR_EXCEP", e.what());
}
catch (const Json::exception& e)
{
- std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType
- << " ERROR=" << e.what() << "\n";
+ error(
+ "Failed parsing PDR JSON file, TYPE={PDR_TYPE} ERROR={ERR_EXCEP}",
+ "PDR_TYPE", pdrType, "ERR_EXCEP", e.what());
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
}
catch (const std::exception& e)
{
- std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType
- << " ERROR=" << e.what() << "\n";
+ error(
+ "Failed parsing PDR JSON file, TYPE= {PDR_TYPE} ERROR={ERR_EXCEP}",
+ "PDR_TYPE", pdrType, "ERR_EXCEP", e.what());
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
}
@@ -238,8 +245,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
- << " ERROR=" << e.what() << "\n";
+ error("Error accessing PDR, HANDLE={REC_HANDLE} ERROR={ERR_EXCEP}",
+ "REC_HANDLE", recordHandle, "ERR_EXCEP", e.what());
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
}
return response;
@@ -738,7 +745,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 false;
}
@@ -764,10 +771,10 @@
if (sensorRearmCount > tmpCompSensorCnt)
{
- std::cerr << "The requester sent wrong sensorRearm"
- << " count for the sensor, SENSOR_ID=" << sensorId
- << "SENSOR_REARM_COUNT=" << (uint16_t)sensorRearmCount
- << "\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",
+ (uint16_t)sensorRearmCount);
break;
}
@@ -803,7 +810,7 @@
PLDM_STATE_EFFECTER_PDR);
if (stateEffecterPDRs.empty())
{
- std::cerr << "Failed to get record by PDR type\n";
+ error("Failed to get record by PDR type");
return false;
}
@@ -829,9 +836,10 @@
if (compEffecterCnt > pdr->composite_effecter_count)
{
- std::cerr << "The requester sent wrong composite effecter"
- << " count for the effecter, EFFECTER_ID=" << effecterId
- << "COMP_EFF_CNT=" << (uint16_t)compEffecterCnt << "\n";
+ error(
+ "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
+ "EFFECTER_ID", effecterId, "COMP_EFF_CNT",
+ (uint16_t)compEffecterCnt);
return false;
}
diff --git a/libpldmresponder/platform.hpp b/libpldmresponder/platform.hpp
index 42ebdb9..74153ac 100644
--- a/libpldmresponder/platform.hpp
+++ b/libpldmresponder/platform.hpp
@@ -17,15 +17,18 @@
#include <libpldm/states.h>
#include <stdint.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <map>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
{
namespace platform
{
-
using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf,
const pldm::utils::Json& json,
pdr_utils::RepoInterface& repo)>;
@@ -313,7 +316,7 @@
getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
if (stateEffecterPDRs.empty())
{
- std::cerr << "Failed to get record by PDR type\n";
+ error("Failed to get record by PDR type");
return PLDM_PLATFORM_INVALID_EFFECTER_ID;
}
@@ -334,11 +337,10 @@
pdr->possible_states);
if (compEffecterCnt > pdr->composite_effecter_count)
{
- std::cerr << "The requester sent wrong composite effecter"
- << " count for the effecter, EFFECTER_ID="
- << (unsigned)effecterId
- << "COMP_EFF_CNT=" << (unsigned)compEffecterCnt
- << "\n";
+ error(
+ "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
+ "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
+ (unsigned)compEffecterCnt);
return PLDM_ERROR_INVALID_DATA;
}
break;
@@ -366,13 +368,12 @@
if (states->possible_states_size < bitfieldIndex ||
!(states->states[bitfieldIndex].byte & (1 << bit)))
{
- std::cerr
- << "Invalid state set value, EFFECTER_ID="
- << (unsigned)effecterId << " VALUE="
- << (unsigned)stateField[currState].effecter_state
- << " COMPOSITE_EFFECTER_ID=" << (unsigned)currState
- << " DBUS_PATH=" << dbusMappings[currState].objectPath
- << "\n";
+ error(
+ "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
+ "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
+ (unsigned)stateField[currState].effecter_state,
+ "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
+ dbusMappings[currState].objectPath.c_str());
rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
break;
}
@@ -391,12 +392,12 @@
}
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;
}
}
@@ -411,8 +412,9 @@
}
catch (const std::out_of_range& e)
{
- std::cerr << "the effecterId does not exist. effecter id: "
- << (unsigned)effecterId << e.what() << '\n';
+ error(
+ "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
+ "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
}
return rc;
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;
}
diff --git a/libpldmresponder/platform_state_effecter.hpp b/libpldmresponder/platform_state_effecter.hpp
index 1e3f3fd..3586d60 100644
--- a/libpldmresponder/platform_state_effecter.hpp
+++ b/libpldmresponder/platform_state_effecter.hpp
@@ -10,9 +10,13 @@
#include <libpldm/platform.h>
#include <libpldm/states.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <cstdint>
#include <map>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace responder
@@ -53,7 +57,7 @@
PLDM_STATE_EFFECTER_PDR);
if (stateEffecterPDRs.empty())
{
- std::cerr << "Failed to get record by PDR type\n";
+ error("Failed to get record by PDR type");
return PLDM_PLATFORM_INVALID_EFFECTER_ID;
}
@@ -73,9 +77,9 @@
pdr->possible_states);
if (compEffecterCnt > pdr->composite_effecter_count)
{
- std::cerr << "The requester sent wrong composite effecter"
- << " count for the effecter, EFFECTER_ID=" << effecterId
- << "COMP_EFF_CNT=" << compEffecterCnt << "\n";
+ error(
+ "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
+ "EFFECTER_ID", effecterId, "COMP_EFF_CNT", compEffecterCnt);
return PLDM_ERROR_INVALID_DATA;
}
break;
@@ -101,12 +105,12 @@
if (states->possible_states_size < bitfieldIndex ||
!(states->states[bitfieldIndex].byte & (1 << bit)))
{
- std::cerr << "Invalid state set value, EFFECTER_ID="
- << effecterId
- << " VALUE=" << stateField[currState].effecter_state
- << " COMPOSITE_EFFECTER_ID=" << currState
- << " DBUS_PATH=" << dbusMappings[currState].objectPath
- << "\n";
+ error(
+ "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
+ "EFFECTER_ID", effecterId, "EFFECTER_STATE",
+ stateField[currState].effecter_state, "CURR_STATE",
+ currState, "DBUS_OBJ_PATH",
+ dbusMappings[currState].objectPath.c_str());
rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
break;
}
@@ -124,11 +128,12 @@
}
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;
}
}
@@ -143,7 +148,8 @@
}
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;
}
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;
}
diff --git a/libpldmresponder/test/meson.build b/libpldmresponder/test/meson.build
index d872fe7..740e307 100644
--- a/libpldmresponder/test/meson.build
+++ b/libpldmresponder/test/meson.build
@@ -41,6 +41,7 @@
gmock,
nlohmann_json,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
sdeventplus,
sdbusplus]),
workdir: meson.current_source_dir())