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/fw-update/update_manager.cpp b/fw-update/update_manager.cpp
index e526ba1..412a420 100644
--- a/fw-update/update_manager.cpp
+++ b/fw-update/update_manager.cpp
@@ -4,12 +4,16 @@
#include "common/utils.hpp"
#include "package_parser.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <cassert>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <string>
+PHOSPHOR_LOG2_USING;
+
namespace pldm
{
@@ -35,9 +39,9 @@
if (activation->activation() ==
software::Activation::Activations::Activating)
{
- std::cerr
- << "Activation of PLDM FW update package already in progress"
- << ", PACKAGE_VERSION=" << parser->pkgVersion << "\n";
+ error(
+ "Activation of PLDM FW update package already in progress, PACKAGE_VERSION={PKG_VERS}",
+ "PKG_VERS", parser->pkgVersion);
std::filesystem::remove(packageFilePath);
return -1;
}
@@ -51,9 +55,9 @@
std::ios::binary | std::ios::in | std::ios::ate);
if (!package.good())
{
- std::cerr << "Opening the PLDM FW update package failed, ERR="
- << unsigned(errno) << ", PACKAGEFILE=" << packageFilePath
- << "\n";
+ error(
+ "Opening the PLDM FW update package failed, ERR={ERR}, PACKAGEFILE={PKG_FILE}",
+ "ERR", unsigned(errno), "PKG_FILE", packageFilePath.c_str());
package.close();
std::filesystem::remove(packageFilePath);
return -1;
@@ -62,9 +66,9 @@
uintmax_t packageSize = package.tellg();
if (packageSize < sizeof(pldm_package_header_information))
{
- std::cerr << "PLDM FW update package length less than the length of "
- "the package header information, PACKAGESIZE="
- << packageSize << "\n";
+ error(
+ "PLDM FW update package length less than the length of the package header information, PACKAGESIZE={PKG_SIZE}",
+ "PKG_SIZE", packageSize);
package.close();
std::filesystem::remove(packageFilePath);
return -1;
@@ -89,8 +93,7 @@
parser = parsePkgHeader(packageHeader);
if (parser == nullptr)
{
- std::cerr << "Invalid PLDM package header information"
- << "\n";
+ error("Invalid PLDM package header information");
package.close();
std::filesystem::remove(packageFilePath);
return -1;
@@ -110,8 +113,7 @@
}
catch (const std::exception& e)
{
- std::cerr << "Invalid PLDM package header"
- << "\n";
+ error("Invalid PLDM package header");
activation = std::make_unique<Activation>(
pldm::utils::DBusHandler::getBus(), objPath,
software::Activation::Activations::Invalid, this);
@@ -125,9 +127,8 @@
totalNumComponentUpdates);
if (!deviceUpdaterInfos.size())
{
- std::cerr
- << "No matching devices found with the PLDM firmware update package"
- << "\n";
+ error(
+ "No matching devices found with the PLDM firmware update package");
activation = std::make_unique<Activation>(
pldm::utils::DBusHandler::getBus(), objPath,
software::Activation::Activations::Invalid, this);
@@ -203,11 +204,10 @@
}
auto endTime = std::chrono::steady_clock::now();
- std::cerr << "Firmware update time: "
- << std::chrono::duration<double, std::milli>(endTime -
- startTime)
- .count()
- << " ms\n";
+ auto dur =
+ std::chrono::duration<double, std::milli>(endTime - startTime)
+ .count();
+ error("Firmware update time: {DURATION}ms", "DURATION", dur);
activation->activation(software::Activation::Activations::Active);
}
return;