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