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/fru_parser.cpp b/libpldmresponder/fru_parser.cpp
index aa85dc8..13f740e 100644
--- a/libpldmresponder/fru_parser.cpp
+++ b/libpldmresponder/fru_parser.cpp
@@ -1,23 +1,23 @@
#include "fru_parser.hpp"
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
+PHOSPHOR_LOG2_USING;
+
using namespace pldm::responder::dbus;
namespace pldm
{
-
namespace responder
{
-
namespace fru_parser
{
-
using Json = nlohmann::json;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -50,8 +50,9 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing FRU Dbus Lookup Map config file failed, FILE="
- << masterJsonPath;
+ error(
+ "Parsing FRU Dbus Lookup Map config file failed, FILE={JSON_PATH}",
+ "JSON_PATH", masterJsonPath.c_str());
std::abort();
}
std::map<Interface, EntityType> defIntfToEntityType;
@@ -66,7 +67,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "FRU DBus lookup map format error\n";
+ error("FRU DBus lookup map format error");
throw InternalFailure();
}
}
@@ -118,7 +119,8 @@
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- std::cerr << "Parsing FRU config file failed, FILE=" << file.path();
+ error("Parsing FRU config file failed, FILE={FILE_PATH}",
+ "FILE_PATH", file.path().c_str());
throw InternalFailure();
}