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