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/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)
{