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