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/gpio.cpp b/gpio.cpp
index 81bc4f5..265ac74 100644
--- a/gpio.cpp
+++ b/gpio.cpp
@@ -20,7 +20,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <cassert>
@@ -48,7 +48,7 @@
if (rc < 0)
{
auto e = errno;
- log<level::ERR>("Failed GET_LINE_VALUES ioctl", entry("ERRNO=%d", e));
+ lg2::error("Failed GET_LINE_VALUES ioctl ERRNO={ERRNO}", "ERRNO", e);
elog<InternalFailure>();
}
@@ -68,7 +68,7 @@
if (rc == -1)
{
auto e = errno;
- log<level::ERR>("Failed SET_LINE_VALUES ioctl", entry("ERRNO=%d", e));
+ lg2::error("Failed SET_LINE_VALUES ioctl ERRNO={ERRNO}", "ERRNO", e);
elog<InternalFailure>();
}
}
@@ -85,9 +85,8 @@
if (fd() == -1)
{
auto e = errno;
- log<level::ERR>("Failed opening GPIO device",
- entry("DEVICE=%s", device.c_str()),
- entry("ERRNO=%d", e));
+ lg2::error("Failed opening GPIO device DEVICE={DEVICE} ERRNO={ERRNO}",
+ "DEVICE", device, "ERRNO", e);
elog<InternalFailure>();
}
@@ -112,8 +111,8 @@
if (rc == -1)
{
auto e = errno;
- log<level::ERR>("Failed GET_LINEHANDLE ioctl", entry("GPIO=%d", gpio),
- entry("ERRNO=%d", e));
+ lg2::error("Failed GET_LINEHANDLE ioctl GPIO={GPIO} ERRNO={ERRNO}",
+ "GPIO", gpio, "ERRNO", e);
elog<InternalFailure>();
}
diff --git a/phosphor-regulators/src/interfaces/manager_interface.cpp b/phosphor-regulators/src/interfaces/manager_interface.cpp
index 81196c1..2c1f530 100644
--- a/phosphor-regulators/src/interfaces/manager_interface.cpp
+++ b/phosphor-regulators/src/interfaces/manager_interface.cpp
@@ -16,7 +16,7 @@
#include "manager_interface.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/sdbus.hpp>
#include <sdbusplus/server.hpp>
@@ -61,8 +61,7 @@
else
{
// The message or context were null
- using namespace phosphor::logging;
- log<level::ERR>("Unable to service Configure method callback");
+ lg2::error("Unable to service Configure method callback");
return -1;
}
@@ -96,8 +95,7 @@
else
{
// The message or context were null
- using namespace phosphor::logging;
- log<level::ERR>("Unable to service Monitor method callback");
+ lg2::error("Unable to service Monitor method callback");
return -1;
}
diff --git a/phosphor-regulators/src/journal.hpp b/phosphor-regulators/src/journal.hpp
index 2199c8c..300ef6f 100644
--- a/phosphor-regulators/src/journal.hpp
+++ b/phosphor-regulators/src/journal.hpp
@@ -17,7 +17,7 @@
#include <systemd/sd-journal.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <string>
#include <vector>
@@ -126,8 +126,7 @@
/** @copydoc Journal::logDebug(const std::string&) */
virtual void logDebug(const std::string& message) override
{
- using namespace phosphor::logging;
- log<level::DEBUG>(message.c_str());
+ lg2::debug(message.c_str());
}
/** @copydoc Journal::logDebug(const std::vector<std::string>&) */
@@ -142,8 +141,7 @@
/** @copydoc Journal::logError(const std::string&) */
virtual void logError(const std::string& message) override
{
- using namespace phosphor::logging;
- log<level::ERR>(message.c_str());
+ lg2::error(message.c_str());
}
/** @copydoc Journal::logError(const std::vector<std::string>&) */
@@ -158,8 +156,7 @@
/** @copydoc Journal::logInfo(const std::string&) */
virtual void logInfo(const std::string& message) override
{
- using namespace phosphor::logging;
- log<level::INFO>(message.c_str());
+ lg2::info(message.c_str());
}
/** @copydoc Journal::logInfo(const std::vector<std::string>&) */
diff --git a/pmbus.cpp b/pmbus.cpp
index 6021a26..7bdda54 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -17,6 +17,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/Device/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -100,10 +101,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>((std::string("Unable to read PMBus device name "
- "PATH=") +
- path.string())
- .c_str());
+ lg2::error("Unable to read PMBus device name PATH={PATH}", "PATH",
+ path);
}
return name;
@@ -129,7 +128,7 @@
try
{
char* err = nullptr;
- std::string val{1, '\0'};
+ std::string val(1, '\0');
file.open(path);
file.read(&val[0], 1);
@@ -138,10 +137,9 @@
if (*err)
{
- log<level::ERR>((std::string("Invalid character in sysfs file"
- " FILE=") +
- path.string() + std::string(" CONTENTS=") + val)
- .c_str());
+ lg2::error(
+ "Invalid character in sysfs file FILE={FILE} CONTENTS={CONTENTS}",
+ "FILE", path, "CONTENTS", val);
// Catch below and handle as a read failure
elog<InternalFailure>();
@@ -151,11 +149,9 @@
{
auto rc = errno;
- log<level::ERR>(
- (std::string("Failed to read sysfs file "
- "errno=") +
- std::to_string(rc) + std::string(" FILENAME=") + path.string())
- .c_str());
+ lg2::error(
+ "Failed to read sysfs file errno={ERRNO} FILENAME={FILENAME}",
+ "ERRNO", rc, "FILENAME", path);
using metadata = xyz::openbmc_project::Common::Device::ReadFailure;
@@ -195,10 +191,9 @@
if (errTrace)
{
- log<level::ERR>((std::string("Failed to read sysfs file "
- "errno=") +
- std::to_string(rc) + " FILENAME=" + path.string())
- .c_str());
+ lg2::error(
+ "Failed to read sysfs file errno={ERRNO} FILENAME={FILENAME}",
+ "ERRNO", rc, "FILENAME", path);
using metadata = xyz::openbmc_project::Common::Device::ReadFailure;
@@ -233,10 +228,9 @@
catch (const std::exception& e)
{
auto rc = errno;
- log<level::ERR>((std::string("Failed to read sysfs file "
- "errno=") +
- std::to_string(rc) + " FILENAME=" + path.string())
- .c_str());
+ lg2::error(
+ "Failed to read sysfs file errno={ERRNO} FILENAME={FILENAME}",
+ "ERRNO", rc, "FILENAME", path);
using metadata = xyz::openbmc_project::Common::Device::ReadFailure;
@@ -274,11 +268,9 @@
else if (ferror(file.get()))
{
auto rc = errno;
- log<level::ERR>(
- (std::string("Failed to read sysfs file "
- "errno=") +
- std::to_string(rc) + " FILENAME=" + path.string())
- .c_str());
+ lg2::error(
+ "Failed to read sysfs file errno={ERRNO} FILENAME={FILENAME}",
+ "ERRNO", rc, "FILENAME", path);
using metadata =
xyz::openbmc_project::Common::Device::ReadFailure;
@@ -311,10 +303,9 @@
catch (const std::exception& e)
{
auto rc = errno;
- log<level::ERR>((std::string("Failed to write sysfs file "
- "errno=") +
- std::to_string(rc) + " FILENAME=" + path.string())
- .c_str());
+ lg2::error(
+ "Failed to write sysfs file errno={ERRNO} FILENAME={FILENAME}",
+ "ERRNO", rc, "FILENAME", path);
using metadata = xyz::openbmc_project::Common::Device::WriteFailure;
@@ -339,20 +330,16 @@
{
// I need to specify binary mode when I construct the ofstream
file.open(path, std::ios::out | std::ios_base::binary);
- log<level::DEBUG>(std::string("Write data to sysfs file "
- "FILENAME=" +
- path.string())
- .c_str());
+ lg2::debug("Write data to sysfs file FILENAME={FILENAME}", "FILENAME",
+ path);
file.write(reinterpret_cast<const char*>(&data[0]), data.size());
}
catch (const std::exception& e)
{
auto rc = errno;
- log<level::ERR>(
- (std::string("Failed to write binary data to sysfs file "
- "errno=") +
- std::to_string(rc) + " FILENAME=" + path.string())
- .c_str());
+ lg2::error(
+ "Failed to write binary data to sysfs file errno={ERRNO} FILENAME={FILENAME}",
+ "ERRNO", rc, "FILENAME", path);
using metadata = xyz::openbmc_project::Common::Device::WriteFailure;
@@ -389,11 +376,9 @@
// and let accesses fail later
if (hwmonDir.empty())
{
- log<level::INFO>(std::string("Unable to find hwmon directory "
- "in device base path"
- " DEVICE_PATH=" +
- basePath.string())
- .c_str());
+ lg2::info("Unable to find hwmon directory in device base path "
+ "DEVICE_PATH={DEVICE_PATH}",
+ "DEVICE_PATH", basePath);
}
}
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;
}
diff --git a/utility.cpp b/utility.cpp
index 0e687dd..c2d7815 100644
--- a/utility.cpp
+++ b/utility.cpp
@@ -51,11 +51,9 @@
{
if (logError)
{
- log<level::ERR>(
- std::string("Error in mapper response for getting service name "
- "PATH=" +
- path + " INTERFACE=" + interface)
- .c_str());
+ lg2::error("Error in mapper response for getting service name "
+ "PATH={PATH} INTERFACE={INTERFACE}",
+ "PATH", path, "INTERFACE", interface);
}
return std::string{};
}
@@ -136,19 +134,13 @@
std::ifstream ifs(path);
if (!ifs.good())
{
- log<level::ERR>(std::string("Unable to open file "
- "PATH=" +
- std::string(path))
- .c_str());
+ lg2::error("Unable to open file PATH={PATH}", "PATH", path);
return nullptr;
}
auto data = json::parse(ifs, nullptr, false);
if (data.is_discarded())
{
- log<level::ERR>(std::string("Failed to parse json "
- "PATH=" +
- std::string(path))
- .c_str());
+ lg2::error("Failed to parse json PATH={PATH}", "PATH", path);
return nullptr;
}
return data;
@@ -197,7 +189,7 @@
}
catch (const std::exception& e)
{
- log<level::INFO>("Failed to get power state.");
+ lg2::info("Failed to get power state.");
}
return state != 0;
}
diff --git a/utility.hpp b/utility.hpp
index e721b9b..d2d9365 100644
--- a/utility.hpp
+++ b/utility.hpp
@@ -4,7 +4,7 @@
#include <nlohmann/json.hpp>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <string>