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/common/flight_recorder.hpp b/common/flight_recorder.hpp
index 2f8ea7d..7cf3ae9 100644
--- a/common/flight_recorder.hpp
+++ b/common/flight_recorder.hpp
@@ -3,16 +3,19 @@
#include <config.h>
#include <common/utils.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>
+
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace flightrecorder
{
-
using ReqOrResponse = bool;
using FlightRecorderData = std::vector<uint8_t>;
using FlightRecorderTimeStamp = std::string;
@@ -91,9 +94,8 @@
if (flightRecorderPolicy)
{
std::ofstream recorderOutputFile(flightRecorderDumpPath);
- std::cout << "Dumping the flight recorder into : "
- << flightRecorderDumpPath << "\n";
-
+ info("Dumping the flight recorder into : {DUMP_PATH}", "DUMP_PATH",
+ flightRecorderDumpPath);
for (const auto& message : tapeRecorder)
{
recorderOutputFile << std::get<FlightRecorderTimeStamp>(message)
@@ -117,7 +119,7 @@
}
else
{
- std::cerr << "Fight recorder policy is disabled\n";
+ error("Fight recorder policy is disabled");
}
}
};
diff --git a/common/test/meson.build b/common/test/meson.build
index b3380b4..9e5517e 100644
--- a/common/test/meson.build
+++ b/common/test/meson.build
@@ -17,6 +17,7 @@
libpldm_dep,
nlohmann_json,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
libpldmutils,
sdbusplus]),
workdir: meson.current_source_dir())
diff --git a/common/utils.cpp b/common/utils.cpp
index 976fd80..7d06fa8 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -5,6 +5,7 @@
#include <libpldm/pdr.h>
#include <libpldm/pldm_types.h>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <algorithm>
@@ -18,6 +19,8 @@
#include <string>
#include <vector>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace utils
@@ -73,8 +76,8 @@
}
catch (const std::exception& e)
{
- std::cerr << " Failed to obtain a record. ERROR =" << e.what()
- << std::endl;
+ error(" Failed to obtain a record. ERROR = {ERR_EXCEP}", "ERR_EXCEP",
+ e.what());
}
return pdrs;
@@ -127,8 +130,8 @@
}
catch (const std::exception& e)
{
- std::cerr << " Failed to obtain a record. ERROR =" << e.what()
- << std::endl;
+ error(" Failed to obtain a record. ERROR = {ERR_EXCEP}", "ERR_EXCEP",
+ e.what());
}
return pdrs;
@@ -140,7 +143,8 @@
std::ifstream eidFile{HOST_EID_PATH};
if (!eidFile.good())
{
- std::cerr << "Could not open host EID file: " << HOST_EID_PATH << "\n";
+ error("Could not open host EID file: {HOST_PATH}", "HOST_PATH",
+ static_cast<std::string>(HOST_EID_PATH));
}
else
{
@@ -152,8 +156,7 @@
}
else
{
- std::cerr << "Host EID file was empty"
- << "\n";
+ error("Host EID file was empty");
}
}
@@ -267,8 +270,9 @@
}
catch (const std::exception& e)
{
- std::cerr << "failed to make a d-bus call to create error log, ERROR="
- << e.what() << "\n";
+ error(
+ "failed to make a d-bus call to create error log, ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
}
@@ -402,7 +406,8 @@
}
else
{
- std::cerr << "Unknown D-Bus property type, TYPE=" << type << "\n";
+ error("Unknown D-Bus property type, TYPE={OTHER_TYPE}", "OTHER_TYPE",
+ type);
}
return propValue;
@@ -465,8 +470,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Error emitting pldm event signal:"
- << "ERROR=" << e.what() << "\n";
+ error("Error emitting pldm event signal:ERROR={ERR_EXCEP}", "ERR_EXCEP",
+ e.what());
return PLDM_ERROR;
}
@@ -594,8 +599,9 @@
}
catch (const sdbusplus::exception::SdBusError& e)
{
- std::cerr << "Failed to check for FRU presence for " << objPath
- << " ERROR =" << e.what() << std::endl;
+ error(
+ "Failed to check for FRU presence for {OBJ_PATH} ERROR = {ERR_EXCEP}",
+ "OBJ_PATH", objPath.c_str(), "ERR_EXCEP", e.what());
}
return isPresent;
}
diff --git a/fw-update/device_updater.cpp b/fw-update/device_updater.cpp
index 8c468a1..6123365 100644
--- a/fw-update/device_updater.cpp
+++ b/fw-update/device_updater.cpp
@@ -5,8 +5,12 @@
#include <libpldm/firmware_update.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <functional>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
@@ -45,8 +49,8 @@
if (rc)
{
updateManager->requester.markFree(eid, instanceId);
- std::cerr << "encode_request_update_req failed, EID=" << unsigned(eid)
- << ", RC=" << rc << "\n";
+ error("encode_request_update_req failed, EID = {EID}, RC = {RC}", "EID",
+ unsigned(eid), "RC", rc);
// Handle error scenario
}
@@ -55,8 +59,8 @@
std::move(std::bind_front(&DeviceUpdater::requestUpdate, this)));
if (rc)
{
- std::cerr << "Failed to send RequestUpdate request, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error("Failed to send RequestUpdate request, EID = {EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
// Handle error scenario
}
}
@@ -67,8 +71,8 @@
if (response == nullptr || !respMsgLen)
{
// Handle error scenario
- std::cerr << "No response received for RequestUpdate, EID="
- << unsigned(eid) << "\n";
+ error("No response received for RequestUpdate, EID = {EID}", "EID",
+ unsigned(eid));
return;
}
@@ -80,16 +84,15 @@
&fdMetaDataLen, &fdWillSendPkgData);
if (rc)
{
- std::cerr << "Decoding RequestUpdate response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Decoding RequestUpdate response failed, EID = {EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
if (completionCode)
{
- std::cerr << "RequestUpdate response failed with error "
- "completion code, EID="
- << unsigned(eid) << ", CC=" << unsigned(completionCode)
- << "\n";
+ error(
+ "RequestUpdate response failed with error completion code, EID = {EID}, CC = {CC}",
+ "EID", unsigned(eid), "CC", unsigned(completionCode));
return;
}
@@ -168,8 +171,8 @@
if (rc)
{
updateManager->requester.markFree(eid, instanceId);
- std::cerr << "encode_pass_component_table_req failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("encode_pass_component_table_req failed, EID = {EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
// Handle error scenario
}
@@ -179,8 +182,9 @@
std::move(std::bind_front(&DeviceUpdater::passCompTable, this)));
if (rc)
{
- std::cerr << "Failed to send PassComponentTable request, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error(
+ "Failed to send PassComponentTable request, EID = {EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
// Handle error scenario
}
}
@@ -191,8 +195,8 @@
if (response == nullptr || !respMsgLen)
{
// Handle error scenario
- std::cerr << "No response received for PassComponentTable, EID="
- << unsigned(eid) << "\n";
+ error("No response received for PassComponentTable, EID = {EID}", "EID",
+ unsigned(eid));
return;
}
@@ -206,17 +210,17 @@
if (rc)
{
// Handle error scenario
- std::cerr << "Decoding PassComponentTable response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Decoding PassComponentTable response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
if (completionCode)
{
// Handle error scenario
- std::cerr << "PassComponentTable response failed with error "
- "completion code, EID="
- << unsigned(eid) << ", CC=" << unsigned(completionCode)
- << "\n";
+ error(
+ "PassComponentTable response failed with error completion code, EID = {EID}, CC = {CC}",
+ "EID", unsigned(eid), "CC", unsigned(completionCode));
return;
}
// Handle ComponentResponseCode
@@ -294,8 +298,8 @@
if (rc)
{
updateManager->requester.markFree(eid, instanceId);
- std::cerr << "encode_update_component_req failed, EID=" << unsigned(eid)
- << ", RC=" << rc << "\n";
+ error("encode_update_component_req failed, EID={EID}, RC = {RC}", "EID",
+ unsigned(eid), "RC", rc);
// Handle error scenario
}
@@ -304,8 +308,8 @@
std::move(std::bind_front(&DeviceUpdater::updateComponent, this)));
if (rc)
{
- std::cerr << "Failed to send UpdateComponent request, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error("Failed to send UpdateComponent request, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
// Handle error scenario
}
}
@@ -316,8 +320,8 @@
if (response == nullptr || !respMsgLen)
{
// Handle error scenario
- std::cerr << "No response received for updateComponent, EID="
- << unsigned(eid) << "\n";
+ error("No response received for updateComponent, EID={EID}", "EID",
+ unsigned(eid));
return;
}
@@ -333,16 +337,15 @@
&timeBeforeReqFWData);
if (rc)
{
- std::cerr << "Decoding UpdateComponent response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Decoding UpdateComponent response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
if (completionCode)
{
- std::cerr << "UpdateComponent response failed with error "
- "completion code, EID="
- << unsigned(eid) << ", CC=" << unsigned(completionCode)
- << "\n";
+ error(
+ "UpdateComponent response failed with error completion code, EID = {EID}, CC = {CC}",
+ "EID", unsigned(eid), "CC", unsigned(completionCode));
return;
}
}
@@ -359,15 +362,17 @@
&length);
if (rc)
{
- std::cerr << "Decoding RequestFirmwareData request failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Decoding RequestFirmwareData request failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
rc = encode_request_firmware_data_resp(
request->hdr.instance_id, PLDM_ERROR_INVALID_DATA, responseMsg,
sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding RequestFirmwareData response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding RequestFirmwareData response failed, EID = {EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
return response;
}
@@ -377,9 +382,8 @@
const auto& comp = compImageInfos[applicableComponents[componentIndex]];
auto compOffset = std::get<5>(comp);
auto compSize = std::get<6>(comp);
- std::cerr << "offset = " << unsigned(offset)
- << ", length = " << unsigned(length) << "\n";
-
+ error("offset = {OFFSET}, length = {LEN}", "OFFSET", unsigned(offset),
+ "LEN", unsigned(length));
if (length < PLDM_FWUP_BASELINE_TRANSFER_SIZE || length > maxTransferSize)
{
rc = encode_request_firmware_data_resp(
@@ -387,8 +391,9 @@
responseMsg, sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding RequestFirmwareData response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding RequestFirmwareData response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
return response;
}
@@ -400,8 +405,9 @@
sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding RequestFirmwareData response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding RequestFirmwareData response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
return response;
}
@@ -424,8 +430,9 @@
sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding RequestFirmwareData response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding RequestFirmwareData response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return response;
}
@@ -444,15 +451,16 @@
decode_transfer_complete_req(request, payloadLength, &transferResult);
if (rc)
{
- std::cerr << "Decoding TransferComplete request failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Decoding TransferComplete request failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
rc = encode_transfer_complete_resp(request->hdr.instance_id,
PLDM_ERROR_INVALID_DATA, responseMsg,
sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding TransferComplete response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding TransferComplete response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
return response;
}
@@ -464,22 +472,24 @@
if (transferResult == PLDM_FWUP_TRANSFER_SUCCESS)
{
- std::cout << "Component Transfer complete, EID=" << unsigned(eid)
- << ", COMPONENT_VERSION=" << compVersion << "\n";
+ info(
+ "Component Transfer complete, EID = {EID}, COMPONENT_VERSION = {COMP_VERS}",
+ "EID", unsigned(eid), "COMP_VERS", compVersion);
}
else
{
- std::cerr << "Transfer of the component failed, EID=" << unsigned(eid)
- << ", COMPONENT_VERSION=" << compVersion
- << ", TRANSFER_RESULT=" << unsigned(transferResult) << "\n";
+ error(
+ "Transfer of the component failed, EID={EID}, COMPONENT_VERSION = {COMP_VERS}, TRANSFER_RESULT = {TRANS_RES}",
+ "EID", unsigned(eid), "COMP_VERS", compVersion, "TRANS_RES",
+ unsigned(transferResult));
}
rc = encode_transfer_complete_resp(request->hdr.instance_id, completionCode,
responseMsg, sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding TransferComplete response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Encoding TransferComplete response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return response;
}
@@ -497,15 +507,16 @@
auto rc = decode_verify_complete_req(request, payloadLength, &verifyResult);
if (rc)
{
- std::cerr << "Decoding VerifyComplete request failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Decoding VerifyComplete request failed, EID = {EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
rc = encode_verify_complete_resp(request->hdr.instance_id,
PLDM_ERROR_INVALID_DATA, responseMsg,
sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding VerifyComplete response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding VerifyComplete response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
return response;
}
@@ -517,22 +528,24 @@
if (verifyResult == PLDM_FWUP_VERIFY_SUCCESS)
{
- std::cout << "Component verification complete, EID=" << unsigned(eid)
- << ", COMPONENT_VERSION=" << compVersion << "\n";
+ info(
+ "Component verification complete, EID={EID}, COMPONENT_VERSION={COMP_VERS}",
+ "EID", unsigned(eid), "COMP_VERS", compVersion);
}
else
{
- std::cerr << "Component verification failed, EID=" << unsigned(eid)
- << ", COMPONENT_VERSION=" << compVersion
- << ", VERIFY_RESULT=" << unsigned(verifyResult) << "\n";
+ error(
+ "Component verification failed, EID={EID}, COMPONENT_VERSION={COMP_VERS}, VERIFY_RESULT={VERIFY_RES}",
+ "EID", unsigned(eid), "COMP_VERS", compVersion, "VERIFY_RES",
+ unsigned(verifyResult));
}
rc = encode_verify_complete_resp(request->hdr.instance_id, completionCode,
responseMsg, sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding VerifyComplete response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Encoding VerifyComplete response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return response;
}
@@ -552,15 +565,16 @@
&compActivationModification);
if (rc)
{
- std::cerr << "Decoding ApplyComplete request failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Decoding ApplyComplete request failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
rc = encode_apply_complete_resp(request->hdr.instance_id,
PLDM_ERROR_INVALID_DATA, responseMsg,
sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding ApplyComplete response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Encoding ApplyComplete response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
return response;
}
@@ -573,23 +587,25 @@
if (applyResult == PLDM_FWUP_APPLY_SUCCESS ||
applyResult == PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD)
{
- std::cout << "Component apply complete, EID=" << unsigned(eid)
- << ", COMPONENT_VERSION=" << compVersion << "\n";
+ info(
+ "Component apply complete, EID = {EID}, COMPONENT_VERSION = {COMP_VERS}",
+ "EID", unsigned(eid), "COMP_VERS", compVersion);
updateManager->updateActivationProgress();
}
else
{
- std::cerr << "Component apply failed, EID=" << unsigned(eid)
- << ", COMPONENT_VERSION=" << compVersion
- << ", APPLY_RESULT=" << unsigned(applyResult) << "\n";
+ error(
+ "Component apply failed, EID = {EID}, COMPONENT_VERSION = {COMP_VERS}, APPLY_RESULT = {APPLY_RES}",
+ "EID", unsigned(eid), "COMP_VERS", compVersion, "APPLY_RES",
+ unsigned(applyResult));
}
rc = encode_apply_complete_resp(request->hdr.instance_id, completionCode,
responseMsg, sizeof(completionCode));
if (rc)
{
- std::cerr << "Encoding ApplyComplete response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Encoding ApplyComplete response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return response;
}
@@ -626,8 +642,8 @@
if (rc)
{
updateManager->requester.markFree(eid, instanceId);
- std::cerr << "encode_activate_firmware_req failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("encode_activate_firmware_req failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
rc = updateManager->handler.registerRequest(
@@ -635,8 +651,8 @@
std::move(std::bind_front(&DeviceUpdater::activateFirmware, this)));
if (rc)
{
- std::cerr << "Failed to send ActivateFirmware request, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error("Failed to send ActivateFirmware request, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
}
@@ -646,8 +662,8 @@
if (response == nullptr || !respMsgLen)
{
// Handle error scenario
- std::cerr << "No response received for ActivateFirmware, EID="
- << unsigned(eid) << "\n";
+ error("No response received for ActivateFirmware, EID={EID}", "EID",
+ unsigned(eid));
return;
}
@@ -659,17 +675,16 @@
if (rc)
{
// Handle error scenario
- std::cerr << "Decoding ActivateFirmware response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("Decoding ActivateFirmware response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
if (completionCode)
{
// Handle error scenario
- std::cerr << "ActivateFirmware response failed with error "
- "completion code, EID="
- << unsigned(eid) << ", CC=" << unsigned(completionCode)
- << "\n";
+ error(
+ "ActivateFirmware response failed with error completion code, EID = {EID}, CC = {CC}",
+ "EID", unsigned(eid), "CC", unsigned(completionCode));
return;
}
diff --git a/fw-update/inventory_manager.cpp b/fw-update/inventory_manager.cpp
index a8ddb46..ea80e69 100644
--- a/fw-update/inventory_manager.cpp
+++ b/fw-update/inventory_manager.cpp
@@ -5,14 +5,16 @@
#include <libpldm/firmware_update.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <functional>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
-
namespace fw_update
{
-
void InventoryManager::discoverFDs(const std::vector<mctp_eid_t>& eids)
{
for (const auto& eid : eids)
@@ -26,8 +28,9 @@
if (rc)
{
requester.markFree(eid, instanceId);
- std::cerr << "encode_query_device_identifiers_req failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "encode_query_device_identifiers_req failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
continue;
}
@@ -38,8 +41,9 @@
this)));
if (rc)
{
- std::cerr << "Failed to send QueryDeviceIdentifiers request, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error(
+ "Failed to send QueryDeviceIdentifiers request, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
}
}
@@ -50,8 +54,8 @@
{
if (response == nullptr || !respMsgLen)
{
- std::cerr << "No response received for QueryDeviceIdentifiers, EID="
- << unsigned(eid) << "\n";
+ error("No response received for QueryDeviceIdentifiers, EID={EID}",
+ "EID", unsigned(eid));
return;
}
@@ -65,17 +69,17 @@
&descriptorCount, &descriptorPtr);
if (rc)
{
- std::cerr << "Decoding QueryDeviceIdentifiers response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Decoding QueryDeviceIdentifiers response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
if (completionCode)
{
- std::cerr << "QueryDeviceIdentifiers response failed with error "
- "completion code, EID="
- << unsigned(eid) << ", CC=" << unsigned(completionCode)
- << "\n";
+ error(
+ "QueryDeviceIdentifiers response failed with error completion code, EID={EID}, CC = {CC}",
+ "EID", unsigned(eid), "CC", unsigned(completionCode));
return;
}
@@ -90,9 +94,9 @@
&descriptorData);
if (rc)
{
- std::cerr
- << "Decoding descriptor type, length and value failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error(
+ "Decoding descriptor type, length and value failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
@@ -114,9 +118,9 @@
&vendorDefinedDescriptorData);
if (rc)
{
- std::cerr
- << "Decoding Vendor-defined descriptor value failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error(
+ "Decoding Vendor-defined descriptor value failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
@@ -155,8 +159,8 @@
if (rc)
{
requester.markFree(eid, instanceId);
- std::cerr << "encode_get_firmware_parameters_req failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error("encode_get_firmware_parameters_req failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
@@ -167,8 +171,9 @@
std::bind_front(&InventoryManager::getFirmwareParameters, this)));
if (rc)
{
- std::cerr << "Failed to send GetFirmwareParameters request, EID="
- << unsigned(eid) << ", RC=" << rc << "\n ";
+ error(
+ "Failed to send GetFirmwareParameters request, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
}
}
@@ -178,8 +183,8 @@
{
if (response == nullptr || !respMsgLen)
{
- std::cerr << "No response received for GetFirmwareParameters, EID="
- << unsigned(eid) << "\n";
+ error("No response received for GetFirmwareParameters, EID={EID}",
+ "EID", unsigned(eid));
descriptorMap.erase(eid);
return;
}
@@ -194,17 +199,17 @@
&pendingCompImageSetVerStr, &compParamTable);
if (rc)
{
- std::cerr << "Decoding GetFirmwareParameters response failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Decoding GetFirmwareParameters response failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
if (fwParams.completion_code)
{
- std::cerr << "GetFirmwareParameters response failed with error "
- "completion code, EID="
- << unsigned(eid)
- << ", CC=" << unsigned(fwParams.completion_code) << "\n";
+ error(
+ "GetFirmwareParameters response failed with error completion code, EID={EID}, CC = {CC}",
+ "EID", unsigned(eid), "CC", unsigned(fwParams.completion_code));
return;
}
@@ -222,8 +227,9 @@
&pendingCompVerStr);
if (rc)
{
- std::cerr << "Decoding component parameter table entry failed, EID="
- << unsigned(eid) << ", RC=" << rc << "\n";
+ error(
+ "Decoding component parameter table entry failed, EID={EID}, RC = {RC}",
+ "EID", unsigned(eid), "RC", rc);
return;
}
@@ -242,4 +248,4 @@
} // namespace fw_update
-} // namespace pldm
\ No newline at end of file
+} // namespace pldm
diff --git a/fw-update/package_parser.cpp b/fw-update/package_parser.cpp
index 3d5d066..7a387ad 100644
--- a/fw-update/package_parser.cpp
+++ b/fw-update/package_parser.cpp
@@ -5,11 +5,14 @@
#include <libpldm/firmware_update.h>
#include <libpldm/utils.h>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <iostream>
#include <memory>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
@@ -39,8 +42,8 @@
&compImageSetVersionStr, &recordDescriptors, &fwDevicePkgData);
if (rc)
{
- std::cerr << "Decoding firmware device ID record failed, RC=" << rc
- << "\n";
+ error("Decoding firmware device ID record failed, RC={RC}", "RC",
+ rc);
throw InternalFailure();
}
@@ -56,9 +59,9 @@
&descriptorType, &descriptorData);
if (rc)
{
- std::cerr
- << "Decoding descriptor type, length and value failed, RC="
- << rc << "\n";
+ error(
+ "Decoding descriptor type, length and value failed, RC={RC}",
+ "RC", rc);
throw InternalFailure();
}
@@ -80,9 +83,9 @@
&descTitleStrType, &descTitleStr, &vendorDefinedDescData);
if (rc)
{
- std::cerr << "Decoding Vendor-defined descriptor value "
- "failed, RC="
- << rc << "\n";
+ error(
+ "Decoding Vendor-defined descriptor value failed, RC={RC}",
+ "RC", rc);
throw InternalFailure();
}
@@ -151,8 +154,8 @@
&compImageInfo, &compVersion);
if (rc)
{
- std::cerr << "Decoding component image information failed, RC="
- << rc << "\n";
+ error("Decoding component image information failed, RC={RC}", "RC",
+ rc);
throw InternalFailure();
}
@@ -194,12 +197,11 @@
if (compLocOffset != calcPkgSize)
{
- std::cerr << "Validating the component location offset failed, "
- "COMP_VERSION="
- << std::get<static_cast<size_t>(
- ComponentImageInfoPos::CompVersionPos)>(
- componentImageInfo)
- << "\n";
+ auto cmpVersion = std::get<static_cast<size_t>(
+ ComponentImageInfoPos::CompVersionPos)>(componentImageInfo);
+ error(
+ "Validating the component location offset failed, COMP_VERSION={COMP_VERS}",
+ "COMP_VERS", cmpVersion);
throw InternalFailure();
}
@@ -208,9 +210,9 @@
if (calcPkgSize != pkgSize)
{
- std::cerr
- << "Package size does not match calculated package size, PKG_SIZE="
- << pkgSize << " ,CALC_PKG_SIZE=" << calcPkgSize << "\n";
+ error(
+ "Package size does not match calculated package size, PKG_SIZE={PKG_SIZE}, CALC_PKG_SIZE={CAL_PKG_SIZE}",
+ "PKG_SIZE", pkgSize, "CAL_PKG_SIZE", calcPkgSize);
throw InternalFailure();
}
}
@@ -220,16 +222,16 @@
{
if (pkgHeaderSize != pkgHdr.size())
{
- std::cerr << "Package header size is invalid, PKG_HDR_SIZE="
- << pkgHeaderSize << "\n";
+ error("Package header size is invalid, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+ "PKG_HDR_SIZE", pkgHeaderSize);
throw InternalFailure();
}
size_t offset = sizeof(pldm_package_header_information) + pkgVersion.size();
if (offset + sizeof(DeviceIDRecordCount) >= pkgHeaderSize)
{
- std::cerr << "Parsing package header failed, PKG_HDR_SIZE="
- << pkgHeaderSize << "\n";
+ error("Parsing package header failed, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+ "PKG_HDR_SIZE", pkgHeaderSize);
throw InternalFailure();
}
@@ -239,15 +241,15 @@
offset = parseFDIdentificationArea(deviceIdRecCount, pkgHdr, offset);
if (deviceIdRecCount != fwDeviceIDRecords.size())
{
- std::cerr
- << "DeviceIDRecordCount entries not found, DEVICE_ID_REC_COUNT="
- << deviceIdRecCount << "\n";
+ error(
+ "DeviceIDRecordCount entries not found, DEVICE_ID_REC_COUNT={DREC_CNT}",
+ "DREC_CNT", deviceIdRecCount);
throw InternalFailure();
}
if (offset + sizeof(ComponentImageCount) >= pkgHeaderSize)
{
- std::cerr << "Parsing package header failed, PKG_HDR_SIZE="
- << pkgHeaderSize << "\n";
+ error("Parsing package header failed, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+ "PKG_HDR_SIZE", pkgHeaderSize);
throw InternalFailure();
}
@@ -258,15 +260,16 @@
offset = parseCompImageInfoArea(compImageCount, pkgHdr, offset);
if (compImageCount != componentImageInfos.size())
{
- std::cerr << "ComponentImageCount entries not found, COMP_IMAGE_COUNT="
- << compImageCount << "\n";
+ error(
+ "ComponentImageCount entries not found, COMP_IMAGE_COUNT={COMP_IMG_CNT}",
+ "COMP_IMG_CNT", compImageCount);
throw InternalFailure();
}
if (offset + sizeof(PackageHeaderChecksum) != pkgHeaderSize)
{
- std::cerr << "Parsing package header failed, PKG_HDR_SIZE="
- << pkgHeaderSize << "\n";
+ error("Parsing package header failed, PKG_HDR_SIZE={PKG_HDR_SIZE}",
+ "PKG_HDR_SIZE", pkgHeaderSize);
throw InternalFailure();
}
@@ -276,8 +279,9 @@
(pkgHdr[offset + 2] << 16) | (pkgHdr[offset + 3] << 24)));
if (calcChecksum != checksum)
{
- std::cerr << "Parsing package header failed, CALC_CHECKSUM="
- << calcChecksum << ", PKG_HDR_CHECKSUM=" << checksum << "\n";
+ error(
+ "Parsing package header failed, CALC_CHECKSUM={CHK_SUM}, PKG_HDR_CHECKSUM={PKG_HDR_CHK_SUM}",
+ "CHK_SUM", calcChecksum, "PKG_HDR_CHK_SUM", checksum);
throw InternalFailure();
}
@@ -297,8 +301,8 @@
&pkgHeader, &pkgVersion);
if (rc)
{
- std::cerr << "Decoding PLDM package header information failed, RC="
- << rc << "\n";
+ error("Decoding PLDM package header information failed, RC={RC}", "RC",
+ rc);
return nullptr;
}
diff --git a/fw-update/test/meson.build b/fw-update/test/meson.build
index b85ed08..9b3cfd6 100644
--- a/fw-update/test/meson.build
+++ b/fw-update/test/meson.build
@@ -27,6 +27,7 @@
libpldmutils,
nlohmann_json,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
sdbusplus,
sdeventplus]),
workdir: meson.current_source_dir())
diff --git a/fw-update/update_manager.cpp b/fw-update/update_manager.cpp
index e526ba1..412a420 100644
--- a/fw-update/update_manager.cpp
+++ b/fw-update/update_manager.cpp
@@ -4,12 +4,16 @@
#include "common/utils.hpp"
#include "package_parser.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <cassert>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <string>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
@@ -35,9 +39,9 @@
if (activation->activation() ==
software::Activation::Activations::Activating)
{
- std::cerr
- << "Activation of PLDM FW update package already in progress"
- << ", PACKAGE_VERSION=" << parser->pkgVersion << "\n";
+ error(
+ "Activation of PLDM FW update package already in progress, PACKAGE_VERSION={PKG_VERS}",
+ "PKG_VERS", parser->pkgVersion);
std::filesystem::remove(packageFilePath);
return -1;
}
@@ -51,9 +55,9 @@
std::ios::binary | std::ios::in | std::ios::ate);
if (!package.good())
{
- std::cerr << "Opening the PLDM FW update package failed, ERR="
- << unsigned(errno) << ", PACKAGEFILE=" << packageFilePath
- << "\n";
+ error(
+ "Opening the PLDM FW update package failed, ERR={ERR}, PACKAGEFILE={PKG_FILE}",
+ "ERR", unsigned(errno), "PKG_FILE", packageFilePath.c_str());
package.close();
std::filesystem::remove(packageFilePath);
return -1;
@@ -62,9 +66,9 @@
uintmax_t packageSize = package.tellg();
if (packageSize < sizeof(pldm_package_header_information))
{
- std::cerr << "PLDM FW update package length less than the length of "
- "the package header information, PACKAGESIZE="
- << packageSize << "\n";
+ error(
+ "PLDM FW update package length less than the length of the package header information, PACKAGESIZE={PKG_SIZE}",
+ "PKG_SIZE", packageSize);
package.close();
std::filesystem::remove(packageFilePath);
return -1;
@@ -89,8 +93,7 @@
parser = parsePkgHeader(packageHeader);
if (parser == nullptr)
{
- std::cerr << "Invalid PLDM package header information"
- << "\n";
+ error("Invalid PLDM package header information");
package.close();
std::filesystem::remove(packageFilePath);
return -1;
@@ -110,8 +113,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "Invalid PLDM package header"
- << "\n";
+ error("Invalid PLDM package header");
activation = std::make_unique<Activation>(
pldm::utils::DBusHandler::getBus(), objPath,
software::Activation::Activations::Invalid, this);
@@ -125,9 +127,8 @@
totalNumComponentUpdates);
if (!deviceUpdaterInfos.size())
{
- std::cerr
- << "No matching devices found with the PLDM firmware update package"
- << "\n";
+ error(
+ "No matching devices found with the PLDM firmware update package");
activation = std::make_unique<Activation>(
pldm::utils::DBusHandler::getBus(), objPath,
software::Activation::Activations::Invalid, this);
@@ -203,11 +204,10 @@
}
auto endTime = std::chrono::steady_clock::now();
- std::cerr << "Firmware update time: "
- << std::chrono::duration<double, std::milli>(endTime -
- startTime)
- .count()
- << " ms\n";
+ auto dur =
+ std::chrono::duration<double, std::milli>(endTime - startTime)
+ .count();
+ error("Firmware update time: {DURATION}ms", "DURATION", dur);
activation->activation(software::Activation::Activations::Active);
}
return;
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index cf3064e..d1125f1 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -4,6 +4,10 @@
#include <libpldm/pldm.h>
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
using namespace pldm::dbus_api;
@@ -40,8 +44,8 @@
if (rc != PLDM_SUCCESS)
{
requester.markFree(mctp_eid, instanceId);
- std::cerr << "Failed to encode_platform_event_message_req, rc = " << rc
- << std::endl;
+ error("Failed to encode_platform_event_message_req, rc = {RC}", "RC",
+ rc);
return;
}
@@ -50,8 +54,7 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr
- << "Failed to receive response for platform event message \n";
+ error("Failed to receive response for platform event message");
return;
}
uint8_t completionCode{};
@@ -60,10 +63,9 @@
&completionCode, &status);
if (rc || completionCode)
{
- std::cerr << "Failed to decode_platform_event_message_resp: "
- << "rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << std::endl;
+ error(
+ "Failed to decode_platform_event_message_resp: rc = {RC}, cc = {CC}",
+ "RC", rc, "CC", static_cast<unsigned>(completionCode));
}
};
@@ -72,7 +74,7 @@
std::move(requestMsg), std::move(platformEventMessageResponseHandler));
if (rc)
{
- std::cerr << "Failed to send the platform event message \n";
+ error("Failed to send the platform event message");
}
}
diff --git a/host-bmc/dbus_to_host_effecters.cpp b/host-bmc/dbus_to_host_effecters.cpp
index 89a8a95..32419a2 100644
--- a/host-bmc/dbus_to_host_effecters.cpp
+++ b/host-bmc/dbus_to_host_effecters.cpp
@@ -4,12 +4,15 @@
#include <libpldm/platform.h>
#include <libpldm/pldm.h>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp>
#include <fstream>
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::utils;
namespace pldm
@@ -38,15 +41,16 @@
fs::path jsonDir(jsonPath);
if (!fs::exists(jsonDir) || fs::is_empty(jsonDir))
{
- std::cerr << "Host Effecter json path does not exist, DIR=" << jsonPath
- << "\n";
+ error("Host Effecter json path does not exist, DIR = {JSON_PATH}",
+ "JSON_PATH", jsonPath.c_str());
return;
}
fs::path jsonFilePath = jsonDir / hostEffecterJson;
if (!fs::exists(jsonFilePath))
{
- std::cerr << "json does not exist, PATH=" << jsonFilePath << "\n";
+ error("json does not exist, PATH = {JSON_PATH}", "JSON_PATH",
+ jsonFilePath.c_str());
throw InternalFailure();
}
@@ -54,7 +58,8 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing json file failed, FILE=" << jsonFilePath << "\n";
+ error("Parsing json file failed, FILE = {JSON_PATH}", "JSON_PATH",
+ jsonFilePath.c_str());
throw InternalFailure();
}
const Json empty{};
@@ -96,11 +101,10 @@
auto states = state.value("state_values", emptyStates);
if (dbusInfo.propertyValues.size() != states.size())
{
- std::cerr << "Number of states do not match with"
- << " number of D-Bus property values in the json. "
- << "Object path " << dbusInfo.dbusMap.objectPath
- << " and property " << dbusInfo.dbusMap.propertyName
- << " will not be monitored \n";
+ error(
+ "Number of states do not match with number of D-Bus property values in the json. Object path {OBJ_PATH} and property {PROP_NAME} will not be monitored",
+ "OBJ_PATH", dbusInfo.dbusMap.objectPath.c_str(),
+ "PROP_NAME", dbusInfo.dbusMap.propertyName);
continue;
}
for (const auto& s : states)
@@ -147,7 +151,7 @@
localOrRemote);
if (effecterId == PLDM_INVALID_EFFECTER_ID)
{
- std::cerr << "Effecter id not found in pdr repo \n";
+ error("Effecter id not found in pdr repo");
return;
}
}
@@ -169,16 +173,16 @@
(currHostState != "xyz.openbmc_project.State.Boot.Progress."
"ProgressStages.SystemSetup"))
{
- std::cout << "Host is not up. Current host state: "
- << currHostState.c_str() << "\n";
+ info("Host is not up. Current host state: {CUR_HOST_STATE}",
+ "CUR_HOST_STATE", currHostState.c_str());
return;
}
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "Error in getting current host state. Will still "
- "continue to set the host effecter - "
- << e.what() << std::endl;
+ error(
+ "Error in getting current host state. Will still continue to set the host effecter - {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
uint8_t newState{};
try
@@ -188,8 +192,7 @@
}
catch (const std::out_of_range& e)
{
- std::cerr << "new state not found in json"
- << "\n";
+ error("New state not found in json");
return;
}
@@ -213,13 +216,12 @@
}
catch (const std::runtime_error& e)
{
- std::cerr << "Could not set host state effecter \n";
+ error("Could not set host state effecter");
return;
}
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Could not set the host state effecter, rc= " << rc
- << " \n";
+ error("Could not set the host state effecter, rc= {RC}", "RC", rc);
}
}
@@ -265,46 +267,46 @@
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Message encode failure. PLDM error code = " << std::hex
- << std::showbase << rc << "\n";
+ error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex,
+ rc);
requester->markFree(mctpEid, instanceId);
return rc;
}
- auto setStateEffecterStatesRespHandler =
- [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) {
- if (response == nullptr || !respMsgLen)
- {
- std::cerr << "Failed to receive response for "
- << "setStateEffecterStates command \n";
- return;
- }
- uint8_t completionCode{};
- auto rc = decode_set_state_effecter_states_resp(
- response, respMsgLen, &completionCode);
- if (rc)
- {
- std::cerr << "Failed to decode setStateEffecterStates response,"
- << " rc " << rc << "\n";
- pldm::utils::reportError(
- "xyz.openbmc_project.bmc.pldm.SetHostEffecterFailed");
- }
- if (completionCode)
- {
- std::cerr << "Failed to set a Host effecter "
- << ", cc=" << static_cast<unsigned>(completionCode)
- << "\n";
- pldm::utils::reportError(
- "xyz.openbmc_project.bmc.pldm.SetHostEffecterFailed");
- }
- };
+ auto setStateEffecterStatesRespHandler = [](mctp_eid_t /*eid*/,
+ const pldm_msg* response,
+ size_t respMsgLen) {
+ if (response == nullptr || !respMsgLen)
+ {
+ error(
+ "Failed to receive response for setStateEffecterStates command");
+ return;
+ }
+ uint8_t completionCode{};
+ auto rc = decode_set_state_effecter_states_resp(response, respMsgLen,
+ &completionCode);
+ if (rc)
+ {
+ error("Failed to decode setStateEffecterStates response, rc {RC}",
+ "RC", rc);
+ pldm::utils::reportError(
+ "xyz.openbmc_project.bmc.pldm.SetHostEffecterFailed");
+ }
+ if (completionCode)
+ {
+ error("Failed to set a Host effecter, cc = {CC}", "CC",
+ static_cast<unsigned>(completionCode));
+ pldm::utils::reportError(
+ "xyz.openbmc_project.bmc.pldm.SetHostEffecterFailed");
+ }
+ };
rc = handler->registerRequest(
mctpEid, instanceId, PLDM_PLATFORM, PLDM_SET_STATE_EFFECTER_STATES,
std::move(requestMsg), std::move(setStateEffecterStatesRespHandler));
if (rc)
{
- std::cerr << "Failed to send request to set an effecter on Host \n";
+ error("Failed to send request to set an effecter on Host");
}
return rc;
}
diff --git a/host-bmc/dbus_to_host_effecters.hpp b/host-bmc/dbus_to_host_effecters.hpp
index f8e165e..11721bb 100644
--- a/host-bmc/dbus_to_host_effecters.hpp
+++ b/host-bmc/dbus_to_host_effecters.hpp
@@ -5,10 +5,14 @@
#include "pldmd/dbus_impl_requester.hpp"
#include "requester/handler.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <string>
#include <utility>
#include <vector>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
@@ -91,8 +95,9 @@
}
catch (const std::exception& e)
{
- std::cerr << "The json file does not exist or malformed, ERROR="
- << e.what() << "\n";
+ error(
+ "The json file does not exist or malformed, ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
}
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 08b78ad..cedebb0 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -6,6 +6,7 @@
#include <libpldm/pldm.h>
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/exception.hpp>
#include <sdeventplus/source/io.hpp>
@@ -13,6 +14,8 @@
#include <fstream>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
using namespace pldm::dbus_api;
@@ -65,7 +68,7 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing Host FRU json file failed" << std::endl;
+ error("Parsing Host FRU json file failed");
}
else
{
@@ -83,8 +86,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "Parsing Host FRU json file failed, exception = "
- << e.what() << std::endl;
+ error("Parsing Host FRU json file failed, exception = {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
}
@@ -177,7 +180,7 @@
if (rc != PLDM_SUCCESS)
{
requester.markFree(mctp_eid, instanceId);
- std::cerr << "Failed to encode_get_pdr_req, rc = " << rc << std::endl;
+ error("Failed to encode_get_pdr_req, rc = {RC}", "RC", rc);
return;
}
@@ -187,7 +190,7 @@
std::move(std::bind_front(&HostPDRHandler::processHostPDRs, this)));
if (rc)
{
- std::cerr << "Failed to send the GetPDR request to Host \n";
+ error("Failed to send the GetPDR request to Host");
}
}
@@ -197,8 +200,7 @@
auto rc = stateSensorHandler.eventAction(entry, state);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Failed to fetch and update D-bus property, rc = " << rc
- << std::endl;
+ error("Failed to fetch and update D-bus property, rc = {RC}", "RC", rc);
return rc;
}
return PLDM_SUCCESS;
@@ -249,8 +251,7 @@
pldm_find_entity_ref_in_tree(entityTree, entities[0], &node);
if (node == nullptr)
{
- std::cerr
- << "\ncould not find referrence of the entity in the tree \n";
+ error("could not find referrence of the entity in the tree");
}
else
{
@@ -308,9 +309,8 @@
&firstEntry, eventData, &actualSize, maxSize);
if (rc != PLDM_SUCCESS)
{
- std::cerr
- << "Failed to encode_pldm_pdr_repository_chg_event_data, rc = "
- << rc << std::endl;
+ error("Failed to encode_pldm_pdr_repository_chg_event_data, rc = {RC}",
+ "RC", rc);
return;
}
auto instanceId = requester.getInstanceId(mctp_eid);
@@ -325,8 +325,8 @@
if (rc != PLDM_SUCCESS)
{
requester.markFree(mctp_eid, instanceId);
- std::cerr << "Failed to encode_platform_event_message_req, rc = " << rc
- << std::endl;
+ error("Failed to encode_platform_event_message_req, rc = {RC}", "RC",
+ rc);
return;
}
@@ -335,9 +335,8 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr << "Failed to receive response for the PDR repository "
- "changed event"
- << "\n";
+ error(
+ "Failed to receive response for the PDR repository changed event");
return;
}
@@ -348,10 +347,9 @@
&completionCode, &status);
if (rc || completionCode)
{
- std::cerr << "Failed to decode_platform_event_message_resp: "
- << "rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << std::endl;
+ error(
+ "Failed to decode_platform_event_message_resp: {RC}, cc = {CC}",
+ "RC", rc, "CC", static_cast<unsigned>(completionCode));
}
};
@@ -360,8 +358,7 @@
std::move(requestMsg), std::move(platformEventMessageResponseHandler));
if (rc)
{
- std::cerr << "Failed to send the PDR repository changed event request"
- << "\n";
+ error("Failed to send the PDR repository changed event request");
}
}
@@ -408,8 +405,7 @@
uint8_t transferCRC{};
if (response == nullptr || !respMsgLen)
{
- std::cerr << "Failed to receive response for the GetPDR"
- " command \n";
+ error("Failed to receive response for the GetPDR command");
return;
}
@@ -422,7 +418,7 @@
memcpy(responsePDRMsg.data(), response, respMsgLen + sizeof(pldm_msg_hdr));
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Failed to decode_get_pdr_resp, rc = " << rc << std::endl;
+ error("Failed to decode_get_pdr_resp, rc = {RC}", "RC", rc);
return;
}
else
@@ -434,10 +430,8 @@
respCount, &transferCRC);
if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
{
- std::cerr << "Failed to decode_get_pdr_resp: "
- << "rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << std::endl;
+ error("Failed to decode_get_pdr_resp: rc = {RC}, cc = {CC}", "RC",
+ rc, "CC", static_cast<unsigned>(completionCode));
return;
}
else
@@ -615,8 +609,8 @@
PLDM_BASE, request);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "GetPLDMVersion encode failure. PLDM error code = "
- << std::hex << std::showbase << rc << "\n";
+ error("GetPLDMVersion encode failure. PLDM error code = {RC}", "RC",
+ lg2::hex, rc);
requester.markFree(mctp_eid, instanceId);
return;
}
@@ -626,13 +620,12 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr << "Failed to receive response for "
- << "getPLDMVersion command, Host seems to be off \n";
+ error(
+ "Failed to receive response for getPLDMVersion command, Host seems to be off");
return;
}
- std::cout << "Getting the response. PLDM RC = " << std::hex
- << std::showbase
- << static_cast<uint16_t>(response->payload[0]) << "\n";
+ info("Getting the response. PLDM RC = {RC}", "RC", lg2::hex,
+ static_cast<uint16_t>(response->payload[0]));
this->responseReceived = true;
getHostPDR();
};
@@ -641,7 +634,7 @@
std::move(getPLDMVersionHandler));
if (rc)
{
- std::cerr << "Failed to discover Host state. Assuming Host as off \n";
+ error("Failed to discover Host state. Assuming Host as off");
}
}
@@ -659,7 +652,7 @@
if (!pdr)
{
- std::cerr << "Failed to get State sensor PDR" << std::endl;
+ error("Failed to get State sensor PDR");
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
return;
@@ -691,9 +684,9 @@
if (rc != PLDM_SUCCESS)
{
requester.markFree(mctp_eid, instanceId);
- std::cerr << "Failed to "
- "encode_get_state_sensor_readings_req, rc = "
- << rc << std::endl;
+ error(
+ "Failed to encode_get_state_sensor_readings_req, rc = {RC}",
+ "RC", rc);
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
return;
@@ -706,8 +699,8 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr << "Failed to receive response for "
- "getStateSensorReading command \n";
+ error(
+ "Failed to receive response for getStateSensorReading command");
return;
}
std::array<get_sensor_state_field, 8> stateField{};
@@ -720,12 +713,10 @@
if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
{
- std::cerr
- << "Failed to "
- "decode_get_state_sensor_readings_resp, rc = "
- << rc
- << " cc=" << static_cast<unsigned>(completionCode)
- << std::endl;
+ error(
+ "Failed to decode_get_state_sensor_readings_resp, rc = {RC} cc = {CC}",
+ "RC", rc, "CC",
+ static_cast<unsigned>(completionCode));
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
}
@@ -765,16 +756,13 @@
}
catch (const std::out_of_range& e)
{
- std::cerr << "No mapping for the events"
- << std::endl;
+ error("No mapping for the events");
}
}
if (sensorOffset > compositeSensorStates.size())
{
- std::cerr
- << " Error Invalid data, Invalid sensor offset"
- << std::endl;
+ error("Error Invalid data, Invalid sensor offset");
return;
}
@@ -783,9 +771,7 @@
if (possibleStates.find(eventState) ==
possibleStates.end())
{
- std::cerr
- << " Error invalid_data, Invalid event state"
- << std::endl;
+ error("Error invalid_data, Invalid event state");
return;
}
const auto& [containerId, entityType, entityInstance] =
@@ -804,9 +790,8 @@
if (rc != PLDM_SUCCESS)
{
- std::cerr << " Failed to send request to get State sensor "
- "reading on Host "
- << std::endl;
+ error(
+ "Failed to send request to get State sensor reading on Host");
}
}
}
diff --git a/host-bmc/test/meson.build b/host-bmc/test/meson.build
index 0bb3b8b..e0973ec 100644
--- a/host-bmc/test/meson.build
+++ b/host-bmc/test/meson.build
@@ -22,6 +22,7 @@
libpldmutils,
nlohmann_json,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
sdbusplus,
sdeventplus]),
workdir: meson.current_source_dir())
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())
diff --git a/meson.build b/meson.build
index c1bda04..251aa8b 100644
--- a/meson.build
+++ b/meson.build
@@ -68,6 +68,7 @@
sdbusplus = dependency('sdbusplus')
sdeventplus = dependency('sdeventplus')
stdplus = dependency('stdplus')
+phosphor_logging_dep = dependency('phosphor-logging')
if cpp.has_header('nlohmann/json.hpp')
nlohmann_json = declare_dependency()
@@ -140,6 +141,7 @@
dependencies: [
libpldm_dep,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
nlohmann_json,
sdbusplus,
],
@@ -157,6 +159,7 @@
libpldmutils,
nlohmann_json,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
sdbusplus,
sdeventplus,
stdplus,
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;
}
diff --git a/oem/ibm/requester/dbus_to_file_handler.cpp b/oem/ibm/requester/dbus_to_file_handler.cpp
index 48157bd..ff632b9 100644
--- a/oem/ibm/requester/dbus_to_file_handler.cpp
+++ b/oem/ibm/requester/dbus_to_file_handler.cpp
@@ -5,6 +5,10 @@
#include <libpldm/file_io.h>
#include <libpldm/pldm.h>
+#include <phosphor-logging/lg2.hpp>
+
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
namespace requester
@@ -35,8 +39,8 @@
{
if (requester == NULL)
{
- std::cerr << "Failed to send resource dump parameters as requester is "
- "not set";
+ error(
+ "Failed to send resource dump parameters as requester is not set");
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
return;
@@ -54,7 +58,7 @@
if (rc != PLDM_SUCCESS)
{
requester->markFree(mctp_eid, instanceId);
- std::cerr << "Failed to encode_new_file_req, rc = " << rc << std::endl;
+ error("Failed to encode_new_file_req, rc = {RC}", "RC", rc);
return;
}
@@ -63,19 +67,16 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr
- << "Failed to receive response for NewFileAvailable command \n";
+ error("Failed to receive response for NewFileAvailable command");
return;
}
uint8_t completionCode{};
auto rc = decode_new_file_resp(response, respMsgLen, &completionCode);
if (rc || completionCode)
{
- std::cerr << "Failed to decode_new_file_resp or"
- << " Host returned error for new_file_available"
- << " rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << "\n";
+ error(
+ "Failed to decode_new_file_resp or Host returned error for new_file_available rc={RC}, cc = {CC}",
+ "RC", rc, "CC", static_cast<unsigned>(completionCode));
reportResourceDumpFailure();
}
};
@@ -84,7 +85,7 @@
std::move(requestMsg), std::move(newFileAvailableRespHandler));
if (rc)
{
- std::cerr << "Failed to send NewFileAvailable Request to Host \n";
+ error("Failed to send NewFileAvailable Request to Host");
reportResourceDumpFailure();
}
}
@@ -102,9 +103,8 @@
}
catch (const std::exception& e)
{
- std::cerr << "failed to set resource dump operation status, "
- "ERROR="
- << e.what() << "\n";
+ error("failed to set resource dump operation status, ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
}
@@ -126,11 +126,11 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "Error " << e.what()
- << " found in getting current resource dump status while "
- "initiating a new resource dump with objPath="
- << resDumpCurrentObjPath.str.c_str()
- << " and intf=" << resDumpProgressIntf << "\n";
+ error(
+ "Error {ERR_EXCEP} found in getting current resource dump status while initiating a new resource dump with objPath={DUMP_OBJ_PATH} and intf={DUMP_PROG_INTF}",
+ "ERR_EXCEP", e.what(), "DUMP_OBJ_PATH",
+ resDumpCurrentObjPath.str.c_str(), "DUMP_PROG_INTF",
+ resDumpProgressIntf);
}
namespace fs = std::filesystem;
@@ -150,8 +150,8 @@
if (!fileHandle)
{
- std::cerr << "resource dump file open error: " << resDumpFilePath
- << "\n";
+ error("resource dump file open error:{RES_DUMP_PATH}", "RES_DUMP_PATH",
+ resDumpFilePath);
PropertyValue value{resDumpStatus};
DBusMapping dbusMapping{resDumpCurrentObjPath, resDumpProgressIntf,
"Status", "string"};
@@ -161,9 +161,9 @@
}
catch (const std::exception& e)
{
- std::cerr << "failed to set resource dump operation status, "
- "ERROR="
- << e.what() << "\n";
+ error(
+ "failed to set resource dump operation status, ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
}
return;
}
@@ -228,7 +228,8 @@
if (!certFile)
{
- std::cerr << "cert file open error: " << certFilePath << "\n";
+ error("cert file open error: {CERT_PATH}", "CERT_PATH",
+ certFilePath.c_str());
return;
}
@@ -248,7 +249,7 @@
{
if (requester == NULL)
{
- std::cerr << "Failed to send csr to host.";
+ error("Failed to send csr to host.");
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
return;
@@ -263,7 +264,7 @@
if (rc != PLDM_SUCCESS)
{
requester->markFree(mctp_eid, instanceId);
- std::cerr << "Failed to encode_new_file_req, rc = " << rc << std::endl;
+ error("Failed to encode_new_file_req, rc = {RC}", "RC", rc);
return;
}
auto newFileAvailableRespHandler = [](mctp_eid_t /*eid*/,
@@ -271,19 +272,17 @@
size_t respMsgLen) {
if (response == nullptr || !respMsgLen)
{
- std::cerr << "Failed to receive response for NewFileAvailable "
- "command for vmi \n";
+ error(
+ "Failed to receive response for NewFileAvailable command for vmi");
return;
}
uint8_t completionCode{};
auto rc = decode_new_file_resp(response, respMsgLen, &completionCode);
if (rc || completionCode)
{
- std::cerr << "Failed to decode_new_file_resp for vmi, or"
- << " Host returned error for new_file_available"
- << " rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << "\n";
+ error(
+ "Failed to decode_new_file_resp for vmi, or Host returned error for new_file_available rc = {RC}, cc = {CC}",
+ "RC", rc, "CC", static_cast<unsigned>(completionCode));
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
}
@@ -293,8 +292,7 @@
std::move(requestMsg), std::move(newFileAvailableRespHandler));
if (rc)
{
- std::cerr
- << "Failed to send NewFileAvailable Request to Host for vmi \n";
+ error("Failed to send NewFileAvailable Request to Host for vmi");
pldm::utils::reportError(
"xyz.openbmc_project.bmc.pldm.InternalFailure");
}
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index e4b2d07..191dd11 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -20,6 +20,7 @@
#include <sys/un.h>
#include <unistd.h>
+#include <phosphor-logging/lg2.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/source/io.hpp>
#include <sdeventplus/source/signal.hpp>
@@ -38,6 +39,8 @@
#include <string>
#include <vector>
+PHOSPHOR_LOG2_USING;
+
#ifdef LIBPLDMRESPONDER
#include "dbus_impl_pdr.hpp"
#include "host-bmc/dbus_to_event_handler.hpp"
@@ -70,8 +73,7 @@
void interruptFlightRecorderCallBack(Signal& /*signal*/,
const struct signalfd_siginfo*)
{
- std::cerr << "\nReceived SIGUR1(10) Signal interrupt\n";
-
+ error("Received SIGUR1(10) Signal interrupt");
// obtain the flight recorder instance and dump the recorder
FlightRecorder::GetInstance().playRecorder();
}
@@ -88,7 +90,7 @@
requestMsg.data() + sizeof(eid) + sizeof(type));
if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields))
{
- std::cerr << "Empty PLDM request header \n";
+ error("Empty PLDM request header");
return std::nullopt;
}
@@ -124,7 +126,7 @@
header.command = hdrFields.command;
if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr))
{
- std::cerr << "Failed adding response header \n";
+ error("Failed adding response header");
return std::nullopt;
}
response.insert(response.end(), completion_code);
@@ -144,9 +146,9 @@
void optionUsage(void)
{
- std::cerr << "Usage: pldmd [options]\n";
- std::cerr << "Options:\n";
- std::cerr << " [--verbose] - would enable verbosity\n";
+ error("Usage: pldmd [options]");
+ error("Options:");
+ error(" [--verbose] - would enable verbosity");
}
int main(int argc, char** argv)
@@ -174,7 +176,7 @@
if (-1 == sockfd)
{
returnCode = -errno;
- std::cerr << "Failed to create the socket, RC= " << returnCode << "\n";
+ error("Failed to create the socket, RC= {RC}", "RC", returnCode);
exit(EXIT_FAILURE);
}
socklen_t optlen;
@@ -187,8 +189,8 @@
&optlen);
if (res == -1)
{
- std::cerr << "Error in obtaining the default send buffer size, Error : "
- << strerror(errno) << std::endl;
+ error("Error in obtaining the default send buffer size, Error : {ERR}",
+ "ERR", strerror(errno));
}
auto event = Event::get_default();
auto& bus = pldm::utils::DBusHandler::getBus();
@@ -293,8 +295,7 @@
if (-1 == result)
{
returnCode = -errno;
- std::cerr << "Failed to connect to the socket, RC= " << returnCode
- << "\n";
+ error("Failed to connect to the socket, RC= {RC}", "RC", returnCode);
exit(EXIT_FAILURE);
}
@@ -302,8 +303,8 @@
if (-1 == result)
{
returnCode = -errno;
- std::cerr << "Failed to send message type as pldm to mctp, RC= "
- << returnCode << "\n";
+ error("Failed to send message type as pldm to mctp, RC= {RC}", "RC",
+ returnCode);
exit(EXIT_FAILURE);
}
@@ -341,7 +342,7 @@
else if (peekedLength <= -1)
{
returnCode = -errno;
- std::cerr << "recv system call failed, RC= " << returnCode << "\n";
+ error("recv system call failed, RC= {RC}", "RC", returnCode);
}
else
{
@@ -392,13 +393,13 @@
sizeof(currentSendbuffSize));
if (res == -1)
{
- std::cerr
- << "Responder : Failed to set the new send buffer size [bytes] : "
- << currentSendbuffSize
- << " from current size [bytes] : "
- << oldBuffSize
- << ", Error : " << strerror(errno)
- << std::endl;
+ error(
+ "Responder : Failed to set the new send buffer size [bytes] : {CURR_SND_BUF_SIZE}",
+ "CURR_SND_BUF_SIZE", currentSendbuffSize);
+ error(
+ "from current size [bytes] : {OLD_BUF_SIZE}, Error : {ERR}",
+ "OLD_BUF_SIZE", oldBuffSize, "ERR",
+ strerror(errno));
return;
}
}
@@ -407,18 +408,17 @@
if (-1 == result)
{
returnCode = -errno;
- std::cerr << "sendto system call failed, RC= "
- << returnCode << "\n";
+ error("sendto system call failed, RC= {RC}", "RC",
+ returnCode);
}
}
}
}
else
{
- std::cerr
- << "Failure to read peeked length packet. peekedLength= "
- << peekedLength << " recvDataLength=" << recvDataLength
- << "\n";
+ error(
+ "Failure to read peeked length packet. peekedLength = {PEEK_LEN}, recvDataLength= {RECV_LEN}",
+ "PEEK_LEN", peekedLength, "RECV_LEN", recvDataLength);
}
}
};
@@ -439,7 +439,7 @@
if (shutdown(sockfd, SHUT_RDWR))
{
- std::perror("Failed to shutdown the socket");
+ error("Failed to shutdown the socket");
}
if (returnCode)
{
diff --git a/requester/handler.hpp b/requester/handler.hpp
index 12c36fe..bdcd7ee 100644
--- a/requester/handler.hpp
+++ b/requester/handler.hpp
@@ -11,6 +11,7 @@
#include <sys/socket.h>
#include <function2/function2.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/timer.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/source/event.hpp>
@@ -21,12 +22,12 @@
#include <tuple>
#include <unordered_map>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
-
namespace requester
{
-
/** @struct RequestKey
*
* RequestKey uniquely identifies the PLDM request message to match it with the
@@ -132,21 +133,20 @@
auto instanceIdExpiryCallBack = [key, this](void) {
if (this->handlers.contains(key))
{
- std::cerr << "Response not received for the request, instance "
- "ID expired."
- << " EID = " << (unsigned)key.eid
- << " INSTANCE_ID = " << (unsigned)key.instanceId
- << " TYPE = " << (unsigned)key.type
- << " COMMAND = " << (unsigned)key.command << "\n";
+ error(
+ "Response not received for the request, instance ID expired. EID = {EID} INSTANCE_ID = {INST_ID} TYPE = {REQ_KEY_TYPE} COMMAND = {REQ_KEY_CMD}",
+ "EID", (unsigned)key.eid, "INST_ID",
+ (unsigned)key.instanceId, "REQ_KEY_TYPE",
+ (unsigned)key.type, "REQ_KEY_CMD", (unsigned)key.command);
auto& [request, responseHandler, timerInstance] =
this->handlers[key];
request->stop();
auto rc = timerInstance->stop();
if (rc)
{
- std::cerr
- << "Failed to stop the instance ID expiry timer. RC = "
- << rc << "\n";
+ error(
+ "Failed to stop the instance ID expiry timer. RC = {RC}",
+ "RC", static_cast<int>(rc));
}
// Call response handler with an empty response to indicate no
// response
@@ -175,8 +175,7 @@
if (rc)
{
requester.markFree(eid, instanceId);
- std::cerr << "Failure to send the PLDM request message"
- << "\n";
+ error("Failure to send the PLDM request message");
return rc;
}
@@ -188,8 +187,9 @@
catch (const std::runtime_error& e)
{
requester.markFree(eid, instanceId);
- std::cerr << "Failed to start the instance ID expiry timer. RC = "
- << e.what() << "\n";
+ error(
+ "Failed to start the instance ID expiry timer. RC = {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
@@ -220,9 +220,8 @@
auto rc = timerInstance->stop();
if (rc)
{
- std::cerr
- << "Failed to stop the instance ID expiry timer. RC = "
- << rc << "\n";
+ error("Failed to stop the instance ID expiry timer. RC = {RC}",
+ "RC", static_cast<int>(rc));
}
responseHandler(eid, response, respMsgLen);
requester.markFree(key.eid, key.instanceId);
diff --git a/requester/request.hpp b/requester/request.hpp
index ffbb169..25e0030 100644
--- a/requester/request.hpp
+++ b/requester/request.hpp
@@ -8,6 +8,7 @@
#include <libpldm/pldm.h>
#include <sys/socket.h>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/timer.hpp>
#include <sdeventplus/event.hpp>
@@ -15,12 +16,12 @@
#include <functional>
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
-
namespace requester
{
-
/** @class RequestRetryTimer
*
* The abstract base class for implementing the PLDM request retry logic. This
@@ -74,8 +75,8 @@
}
catch (const std::runtime_error& e)
{
- std::cerr << "Failed to start the request timer. RC = " << e.what()
- << "\n";
+ error("Failed to start the request timer. RC = {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
@@ -88,8 +89,8 @@
auto rc = timer.stop();
if (rc)
{
- std::cerr << "Failed to stop the request timer. RC = " << rc
- << "\n";
+ error("Failed to stop the request timer. RC = {RC}", "RC",
+ static_cast<int>(rc));
}
}
@@ -186,11 +187,10 @@
sizeof(currentSendbuffSize));
if (res == -1)
{
- std::cerr
- << "Requester : Failed to set the new send buffer size [bytes] : "
- << currentSendbuffSize
- << " from current size [bytes]: " << oldSendbuffSize
- << " , Error : " << strerror(errno) << std::endl;
+ error(
+ "Requester : Failed to set the new send buffer size [bytes] : {CURR_SND_BUF_SIZE} from current size [bytes]: {OLD_BUF_SIZE} , Error : {ERR}",
+ "CURR_SND_BUF_SIZE", currentSendbuffSize, "OLD_BUF_SIZE",
+ oldSendbuffSize, "ERR", strerror(errno));
return PLDM_ERROR;
}
}
@@ -199,8 +199,8 @@
auto rc = pldm_send(eid, fd, requestMsg.data(), requestMsg.size());
if (rc < 0)
{
- std::cerr << "Failed to send PLDM message. RC = " << rc
- << ", errno = " << errno << "\n";
+ error("Failed to send PLDM message. RC = {RC}, errno = {ERR}", "RC",
+ static_cast<int>(rc), "ERR", errno);
return PLDM_ERROR;
}
return PLDM_SUCCESS;
diff --git a/requester/test/meson.build b/requester/test/meson.build
index c5c0168..1e63997 100644
--- a/requester/test/meson.build
+++ b/requester/test/meson.build
@@ -21,6 +21,7 @@
libpldm_dep,
nlohmann_json,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
sdbusplus,
sdeventplus,
test_src]),
diff --git a/softoff/main.cpp b/softoff/main.cpp
index 4ff2a4d..ff6252d 100644
--- a/softoff/main.cpp
+++ b/softoff/main.cpp
@@ -1,8 +1,12 @@
#include "common/utils.hpp"
#include "softoff.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
int main()
{
// Get a default event loop
@@ -18,15 +22,15 @@
if (softPower.isError())
{
- std::cerr << "Host failed to gracefully shutdown, exiting "
- "pldm-softpoweroff app\n";
+ error(
+ "Host failed to gracefully shutdown, exiting pldm-softpoweroff app");
return -1;
}
if (softPower.isCompleted())
{
- std::cerr << "Host current state is not Running, exiting "
- "pldm-softpoweroff app\n";
+ error(
+ "Host current state is not Running, exiting pldm-softpoweroff app");
return 0;
}
@@ -34,9 +38,8 @@
// wait the host gracefully shutdown.
if (softPower.hostSoftOff(event))
{
- std::cerr << "pldm-softpoweroff:Failure in sending soft off request to "
- "the host. Exiting pldm-softpoweroff app\n";
-
+ error(
+ "pldm-softpoweroff:Failure in sending soft off request to the host. Exiting pldm-softpoweroff app");
return -1;
}
@@ -44,10 +47,8 @@
{
pldm::utils::reportError(
"pldm soft off: Waiting for the host soft off timeout");
- std::cerr
- << "PLDM host soft off: ERROR! Wait for the host soft off timeout."
- << "Exit the pldm-softpoweroff "
- << "\n";
+ error(
+ "PLDM host soft off: ERROR! Wait for the host soft off timeout. Exit the pldm-softpoweroff");
return -1;
}
diff --git a/softoff/meson.build b/softoff/meson.build
index a02a306..fb46280 100644
--- a/softoff/meson.build
+++ b/softoff/meson.build
@@ -5,6 +5,7 @@
sdeventplus,
sdbusplus,
phosphor_dbus_interfaces,
+ phosphor_logging_dep,
]
source = ['main.cpp','softoff.cpp']
diff --git a/softoff/softoff.cpp b/softoff/softoff.cpp
index 781ea46..7d83cb6 100644
--- a/softoff/softoff.cpp
+++ b/softoff/softoff.cpp
@@ -9,6 +9,7 @@
#include <libpldm/pldm.h>
#include <libpldm/state_set.h>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/exception.hpp>
@@ -18,9 +19,10 @@
#include <array>
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
-
using namespace sdeventplus;
using namespace sdeventplus::source;
constexpr auto clockId = sdeventplus::ClockId::RealTime;
@@ -42,8 +44,7 @@
auto rc = getEffecterID();
if (completed)
{
- std::cerr
- << "pldm-softpoweroff: effecter to initiate softoff not found \n";
+ error("pldm-softpoweroff: effecter to initiate softoff not found");
return;
}
else if (rc != PLDM_SUCCESS)
@@ -55,8 +56,8 @@
rc = getSensorInfo();
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Message get Sensor PDRs error. PLDM error code = "
- << std::hex << std::showbase << rc << "\n";
+ error("Message get Sensor PDRs error. PLDM error code = {RC}", "RC",
+ lg2::hex, static_cast<int>(rc));
hasError = true;
return;
}
@@ -92,7 +93,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "PLDM host soft off: Can't get current host state.\n";
+ error("PLDM host soft off: Can't get current host state.");
hasError = true;
return PLDM_ERROR;
}
@@ -119,8 +120,8 @@
auto rc = timer.stop();
if (rc < 0)
{
- std::cerr << "PLDM soft off: Failure to STOP the timer. ERRNO="
- << rc << "\n";
+ error("PLDM soft off: Failure to STOP the timer. ERRNO={RC}", "RC",
+ rc);
}
// This marks the completion of pldm soft power off.
@@ -163,8 +164,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "PLDM soft off: Error get VMM PDR,ERROR=" << e.what()
- << "\n";
+ error("PLDM soft off: Error get VMM PDR,ERROR={ERR_EXCEP}", "ERR_EXCEP",
+ e.what());
VMMPdrExist = false;
}
@@ -192,9 +193,7 @@
if (sysFwResponse.size() == 0)
{
- std::cerr
- << "No effecter ID has been found that matches the criteria"
- << "\n";
+ error("No effecter ID has been found that matches the criteria");
return PLDM_ERROR;
}
@@ -207,8 +206,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "PLDM soft off: Error get system firmware PDR,ERROR="
- << e.what() << "\n";
+ error("PLDM soft off: Error get system firmware PDR,ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
completed = true;
return PLDM_ERROR;
}
@@ -243,9 +242,7 @@
if (Response.size() == 0)
{
- std::cerr
- << "No sensor PDR has been found that matches the criteria"
- << "\n";
+ error("No sensor PDR has been found that matches the criteria");
return PLDM_ERROR;
}
@@ -255,7 +252,7 @@
pdr = reinterpret_cast<pldm_state_sensor_pdr*>(rep.data());
if (!pdr)
{
- std::cerr << "Failed to get state sensor PDR.\n";
+ error("Failed to get state sensor PDR.");
return PLDM_ERROR;
}
}
@@ -284,8 +281,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "PLDM soft off: Error get State Sensor PDR,ERROR="
- << e.what() << "\n";
+ error("PLDM soft off: Error get State Sensor PDR,ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
@@ -315,8 +312,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "PLDM soft off: Error get instanceID,ERROR=" << e.what()
- << "\n";
+ error("PLDM soft off: Error get instanceID,ERROR={ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
@@ -331,8 +328,8 @@
instanceID, effecterID, effecterCount, &stateField, request);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Message encode failure. PLDM error code = " << std::hex
- << std::showbase << rc << "\n";
+ error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex,
+ static_cast<int>(rc));
return PLDM_ERROR;
}
@@ -340,8 +337,7 @@
int fd = pldm_open();
if (-1 == fd)
{
- std::cerr << "Failed to connect to mctp demux daemon"
- << "\n";
+ error("Failed to connect to mctp demux daemon");
return PLDM_ERROR;
}
@@ -350,9 +346,8 @@
Timer::TimePoint /*time*/) {
if (!responseReceived)
{
- std::cerr
- << "PLDM soft off: ERROR! Can't get the response for the PLDM request msg. Time out!\n"
- << "Exit the pldm-softpoweroff\n";
+ error(
+ "PLDM soft off: ERROR! Can't get the response for the PLDM request msg. Time out! Exit the pldm-softpoweroff");
exit(-1);
}
return;
@@ -374,8 +369,8 @@
&responseMsgSize);
if (rc)
{
- std::cerr << "Soft off: failed to recv pldm data. PLDM RC = " << rc
- << "\n";
+ error("Soft off: failed to recv pldm data. PLDM RC = {RC}", "RC",
+ static_cast<int>(rc));
return;
}
@@ -388,8 +383,8 @@
auto response = reinterpret_cast<pldm_msg*>(responseMsgPtr.get());
if (response->payload[0] != PLDM_SUCCESS)
{
- std::cerr << "Getting the wrong response. PLDM RC = "
- << (unsigned)response->payload[0] << "\n";
+ error("Getting the wrong response. PLDM RC = {RC}", "RC",
+ (unsigned)response->payload[0]);
exit(-1);
}
@@ -403,15 +398,16 @@
auto ret = startTimer(timeMicroseconds);
if (ret < 0)
{
- std::cerr << "Failure to start Host soft off wait timer, ERRNO = "
- << ret << "Exit the pldm-softpoweroff\n";
+ error(
+ "Failure to start Host soft off wait timer, ERRNO = {RET}. Exit the pldm-softpoweroff",
+ "RET", ret);
exit(-1);
}
else
{
- std::cerr
- << "Timer started waiting for host soft off, TIMEOUT_IN_SEC = "
- << SOFTOFF_TIMEOUT_SECONDS << "\n";
+ error(
+ "Timer started waiting for host soft off, TIMEOUT_IN_SEC = {TIMEOUT_SEC}",
+ "TIMEOUT_SEC", SOFTOFF_TIMEOUT_SECONDS);
}
return;
};
@@ -421,8 +417,9 @@
rc = pldm_send(mctpEID, fd, requestMsg.data(), requestMsg.size());
if (0 > rc)
{
- std::cerr << "Failed to send message/receive response. RC = " << rc
- << ", errno = " << errno << "\n";
+ error(
+ "Failed to send message/receive response. RC = {RC}, errno = {ERR}",
+ "RC", static_cast<int>(rc), "ERR", errno);
return PLDM_ERROR;
}
@@ -435,9 +432,9 @@
}
catch (const sdeventplus::SdEventError& e)
{
- std::cerr
- << "PLDM host soft off: Failure in processing request.ERROR= "
- << e.what() << "\n";
+ error(
+ "PLDM host soft off: Failure in processing request.ERROR= {ERR_EXCEP}",
+ "ERR_EXCEP", e.what());
return PLDM_ERROR;
}
}
diff --git a/subprojects/phosphor-logging.wrap b/subprojects/phosphor-logging.wrap
new file mode 100644
index 0000000..71eee8b
--- /dev/null
+++ b/subprojects/phosphor-logging.wrap
@@ -0,0 +1,6 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-logging.git
+revision = HEAD
+
+[provide]
+phosphor-logging = phosphor_logging_dep
diff --git a/utilities/meson.build b/utilities/meson.build
index c7200c1..1977aa4 100644
--- a/utilities/meson.build
+++ b/utilities/meson.build
@@ -1,4 +1,4 @@
-deps = [ CLI11_dep, libpldm_dep, sdeventplus ]
+deps = [ CLI11_dep, libpldm_dep, sdeventplus, phosphor_logging_dep ]
executable('set-state-effecter', 'requester/set_state_effecter.cpp',
implicit_include_directories: false,
diff --git a/utilities/requester/set_state_effecter.cpp b/utilities/requester/set_state_effecter.cpp
index 7e98c0b..c71f079 100644
--- a/utilities/requester/set_state_effecter.cpp
+++ b/utilities/requester/set_state_effecter.cpp
@@ -2,10 +2,13 @@
#include <libpldm/pldm.h>
#include <CLI/CLI.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <array>
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
int main(int argc, char** argv)
{
CLI::App app{"Send PLDM command SetStateEffecterStates"};
@@ -29,8 +32,8 @@
&stateField, request);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Message encode failure. PLDM error code = " << std::hex
- << std::showbase << rc << "\n";
+ error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex,
+ rc);
return -1;
}
@@ -38,8 +41,7 @@
int fd = pldm_open();
if (-1 == fd)
{
- std::cerr << "Failed to init mctp"
- << "\n";
+ error("Failed to init mctp");
return -1;
}
@@ -50,13 +52,14 @@
&responseMsg, &responseMsgSize);
if (0 > rc)
{
- std::cerr << "Failed to send message/receive response. RC = " << rc
- << ", errno = " << errno << "\n";
+ error(
+ "Failed to send message/receive response. RC = {RC}, errno = {ERR}",
+ "RC", rc, "ERR", errno);
return -1;
}
pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg);
- std::cout << "Done. PLDM RC = " << std::hex << std::showbase
- << static_cast<uint16_t>(response->payload[0]) << std::endl;
+ info("Done. PLDM RC = {RC}", "RC", lg2::hex,
+ static_cast<uint16_t>(response->payload[0]));
free(responseMsg);
return 0;
diff --git a/utilities/requester/set_state_effecter_async.cpp b/utilities/requester/set_state_effecter_async.cpp
index 8b4b58b..8a7a041 100644
--- a/utilities/requester/set_state_effecter_async.cpp
+++ b/utilities/requester/set_state_effecter_async.cpp
@@ -3,6 +3,7 @@
#include <libpldm/pldm.h>
#include <CLI/CLI.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/source/io.hpp>
@@ -11,6 +12,7 @@
using namespace sdeventplus;
using namespace sdeventplus::source;
+PHOSPHOR_LOG2_USING;
int main(int argc, char** argv)
{
@@ -35,8 +37,8 @@
&stateField, request);
if (rc != PLDM_SUCCESS)
{
- std::cerr << "Message encode failure. PLDM error code = " << std::hex
- << std::showbase << rc << "\n";
+ error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex,
+ rc);
return -1;
}
@@ -44,8 +46,7 @@
int fd = pldm_open();
if (-1 == fd)
{
- std::cerr << "Failed to init mctp"
- << "\n";
+ error("Failed to init mctp");
return -1;
}
@@ -67,9 +68,8 @@
// sent out
io.set_enabled(Enabled::Off);
pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg);
- std::cout << "Done. PLDM RC = " << std::hex << std::showbase
- << static_cast<uint16_t>(response->payload[0])
- << std::endl;
+ info("Done. PLDM RC = {RC}", "RC", lg2::hex,
+ static_cast<uint16_t>(response->payload[0]));
free(responseMsg);
exit(EXIT_SUCCESS);
}
@@ -80,8 +80,9 @@
rc = pldm_send(mctpEid, fd, requestMsg.data(), requestMsg.size());
if (0 > rc)
{
- std::cerr << "Failed to send message/receive response. RC = " << rc
- << ", errno = " << errno << "\n";
+ error(
+ "Failed to send message/receive response. RC = {RC} errno = {ERR}",
+ "RC", rc, "ERR", errno);
return -1;
}