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