Move phosphor-regulators, tools, base dir to lg2
Update the logging API for files in phosphor-regulators, tools,
and the base directory from the older phosphor::logging::log
style of journal traces to the newer lg2::log style. Also
fix bug involving corruption of string data in PMBus class.
Tested:
* Verified journal traces worked correctly in simulation
and produced correct journalctl key-value pairs.
* Temporarily modified both json configs and source code to
force various messages, and verified their presence in the
journalctl output.
* Verify that change in PMBus class correctly fixed corrupted
string data by building and running a temporary executable
with the change included.
Change-Id: I9c3e380bf2103c5ddc051a5dc90ba2c0d3f38796
Signed-off-by: Anwaar Hadi <anwaar.hadi@ibm.com>
diff --git a/tools/power-utils/model.cpp b/tools/power-utils/model.cpp
index 7bfda66..507e585 100644
--- a/tools/power-utils/model.cpp
+++ b/tools/power-utils/model.cpp
@@ -22,7 +22,7 @@
#include "utils.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <exception>
#include <format>
@@ -153,7 +153,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(std::format("Error: {}", e.what()).c_str());
+ lg2::error("Error in getModel: {ERROR}", "ERROR", e);
}
return model;
}
diff --git a/tools/power-utils/utils.cpp b/tools/power-utils/utils.cpp
index 82e40b5..d643dbf 100644
--- a/tools/power-utils/utils.cpp
+++ b/tools/power-utils/utils.cpp
@@ -19,13 +19,12 @@
#include "utility.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/Device/error.hpp>
#include <cassert>
#include <exception>
#include <filesystem>
-#include <format>
#include <iomanip>
#include <ios>
#include <iostream>
@@ -96,10 +95,8 @@
}
catch (const std::exception& e)
{
- log<level::WARNING>(
- std::format("Error reading property {}: {}",
- property.first, e.what())
- .c_str());
+ lg2::warning("Error reading property {PROPERTY}: {ERROR}",
+ "PROPERTY", property.first, "ERROR", e);
}
}
@@ -146,9 +143,8 @@
if (vpdValue.size() != vpdSize)
{
- log<level::INFO>(
- std::format(" {} resize needed. size: {}", vpdName, vpdValue.size())
- .c_str());
+ lg2::info(" {VPDNAME} resize needed. size: {SIZE}", "VPDNAME", vpdName,
+ "SIZE", vpdValue.size());
vpdValue.resize(vpdSize, ' ');
}
@@ -167,9 +163,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(std::format("Unable to check for existence of {}: {}",
- filePath, e.what())
- .c_str());
+ lg2::error("Unable to check for existence of {FILEPATH}: {ERROR}",
+ "FILEPATH", filePath, "ERROR", e);
}
return false;
}
@@ -202,7 +197,7 @@
auto devicePath = data["psuDevices"][psuInventoryPath];
if (devicePath.empty())
{
- log<level::WARNING>("Unable to find psu devices or path");
+ lg2::warning("Unable to find psu devices or path");
}
return devicePath;
}
@@ -220,13 +215,12 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("Error in getDevicePath: {}", e.what()).c_str());
+ lg2::error("Error in getDevicePath: {ERROR}", "ERROR", e);
return {};
}
catch (...)
{
- log<level::ERR>("Unknown error occurred in getDevicePath");
+ lg2::error("Unknown error occurred in getDevicePath");
return {};
}
}
diff --git a/tools/power-utils/version.cpp b/tools/power-utils/version.cpp
index 738664d..3a08bc3 100644
--- a/tools/power-utils/version.cpp
+++ b/tools/power-utils/version.cpp
@@ -22,7 +22,7 @@
#include "utils.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <exception>
#include <tuple>
@@ -62,14 +62,14 @@
auto devices = data.find("psuDevices");
if (devices == data.end())
{
- log<level::WARNING>("Unable to find psuDevices");
+ lg2::warning("Unable to find psuDevices");
return {};
}
auto devicePath = devices->find(psuInventoryPath);
if (devicePath == devices->end())
{
- log<level::WARNING>("Unable to find path for PSU",
- entry("PATH=%s", psuInventoryPath.c_str()));
+ lg2::warning("Unable to find path for PSU PATH={PATH}", "PATH",
+ psuInventoryPath);
return {};
}
@@ -87,7 +87,7 @@
}
if (fileName.empty())
{
- log<level::WARNING>("Unable to find Version file");
+ lg2::warning("Unable to find Version file");
return {};
}
return std::make_tuple(*devicePath, type, fileName);
@@ -186,7 +186,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(std::format("Error: {}", e.what()).c_str());
+ lg2::error("Error in getVersion: {ERROR}", "ERROR", e);
}
return version;
}