src: Convert logging to lg2
Change-Id: I28bf669e5139062f0f6145277db65d6821d48e78
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/src/DeviceMgmt.cpp b/src/DeviceMgmt.cpp
index f36b68a..4c690ba 100644
--- a/src/DeviceMgmt.cpp
+++ b/src/DeviceMgmt.cpp
@@ -2,12 +2,13 @@
#include "Utils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <ios>
-#include <iostream>
#include <optional>
#include <sstream>
#include <stdexcept>
@@ -114,7 +115,7 @@
std::ofstream ctor(ctorPath);
if (!ctor.good())
{
- std::cerr << "Failed to open " << ctorPath << "\n";
+ lg2::error("Failed to open '{PATH}'", "PATH", ctorPath);
return -1;
}
@@ -122,7 +123,7 @@
ctor.flush();
if (!ctor.good())
{
- std::cerr << "Failed to write to " << ctorPath << "\n";
+ lg2::error("Failed to write to '{PATH}'", "PATH", ctorPath);
return -1;
}
@@ -147,7 +148,7 @@
std::ofstream dtor(dtorPath);
if (!dtor.good())
{
- std::cerr << "Failed to open " << dtorPath << "\n";
+ lg2::error("Failed to open '{PATH}'", "PATH", dtorPath);
return -1;
}
@@ -155,7 +156,7 @@
dtor.flush();
if (!dtor.good())
{
- std::cerr << "Failed to write to " << dtorPath << "\n";
+ lg2::error("Failed to write to '{PATH}'", "PATH", dtorPath);
return -1;
}
diff --git a/src/DeviceMgmt.hpp b/src/DeviceMgmt.hpp
index 5247486..09644ab 100644
--- a/src/DeviceMgmt.hpp
+++ b/src/DeviceMgmt.hpp
@@ -6,6 +6,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/container/flat_map.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/bus/match.hpp>
#include <sdbusplus/message.hpp>
@@ -13,7 +14,6 @@
#include <cstddef>
#include <cstdint>
#include <functional>
-#include <iostream>
#include <memory>
#include <optional>
#include <stdexcept>
@@ -120,8 +120,8 @@
std::get_if<std::string>(&findSensorName->second);
if (sensorName == nullptr)
{
- std::cerr << "Unable to find sensor name " << name
- << " on path " << path.str << "\n";
+ lg2::info("Unable to find '{NAME}' on '{PATH}'", "NAME", name,
+ "PATH", path.str);
continue;
}
@@ -157,8 +157,8 @@
// ensure that we end up with a fresh instance of it.
if (params->devicePresent())
{
- std::cerr << "Clearing out previous instance for "
- << path.str << "\n";
+ lg2::info("Clearing out previous instance for '{PATH}'",
+ "PATH", path.str);
I2CDevice tmp(*params);
}
@@ -171,9 +171,10 @@
}
catch (std::runtime_error&)
{
- std::cerr << "Failed to instantiate " << params->type->name
- << " at address " << params->address << " on bus "
- << params->bus << "\n";
+ lg2::error(
+ "Failed to instantiate '{NAME}' at address '{ADDR}' on bus '{BUS}'",
+ "NAME", params->type->name, "ADDR", params->address,
+ "BUS", params->bus);
}
}
}
diff --git a/src/FileHandle.cpp b/src/FileHandle.cpp
index 90bf64b..277a062 100644
--- a/src/FileHandle.cpp
+++ b/src/FileHandle.cpp
@@ -3,10 +3,11 @@
#include <fcntl.h>
#include <unistd.h>
+#include <phosphor-logging/lg2.hpp>
+
#include <filesystem>
#include <iostream>
#include <stdexcept>
-#include <string>
FileHandle::FileHandle(const std::filesystem::path& name,
std::ios_base::openmode mode) :
@@ -40,7 +41,7 @@
int r = close(fd);
if (r < 0)
{
- std::cerr << "Failed to close fd " << std::to_string(fd);
+ lg2::error("Failed to close fd: '{FD}'", "FD", fd);
}
}
}
diff --git a/src/PwmSensor.cpp b/src/PwmSensor.cpp
index bffead9..646f0c6 100644
--- a/src/PwmSensor.cpp
+++ b/src/PwmSensor.cpp
@@ -20,13 +20,13 @@
#include "Utils.hpp"
#include "sensor.hpp"
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <cmath>
#include <cstdint>
#include <fstream>
-#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
@@ -168,8 +168,7 @@
valueMutabilityInterface->register_property("Mutable", true);
if (!valueMutabilityInterface->initialize())
{
- std::cerr
- << "error initializing sensor value mutability interface\n";
+ lg2::error("error initializing sensor value mutability interface");
valueMutabilityInterface = nullptr;
}
}
@@ -212,13 +211,13 @@
std::ifstream ref(sysPath);
if (!ref.good())
{
- std::cerr << "Error opening " << sysPath << "\n";
+ lg2::error("Error opening '{PATH}'", "PATH", sysPath);
return 0;
}
std::string line;
if (!std::getline(ref, line))
{
- std::cerr << "Error reading pwm at " << sysPath << "\n";
+ lg2::error("Error reading pwm at '{PATH}'", "PATH", sysPath);
return 0;
}
try
@@ -228,7 +227,7 @@
}
catch (const std::invalid_argument&)
{
- std::cerr << "Error converting pwm\n";
+ lg2::error("Error converting pwm");
// throw if not initial read to be caught by dbus bindings
if (errThrow)
{
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index fc252ac..68233c0 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -8,6 +8,7 @@
#include <boost/asio/error.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/exception.hpp>
@@ -17,7 +18,6 @@
#include <chrono>
#include <cstddef>
#include <cstdint>
-#include <iostream>
#include <limits>
#include <memory>
#include <string>
@@ -111,8 +111,9 @@
if (valueFind == cfg.end() || severityFind == cfg.end() ||
directionFind == cfg.end())
{
- std::cerr << "Malformed threshold on configuration interface "
- << intf << "\n";
+ lg2::error(
+ "Malformed threshold on configuration interface: '{INTERFACE}'",
+ "INTERFACE", intf);
return false;
}
unsigned int severity =
@@ -158,7 +159,7 @@
auto labelFind = result.find("Label");
if (labelFind == result.end())
{
- std::cerr << "No label in threshold configuration\n";
+ lg2::error("No label in threshold configuration");
return;
}
std::string label =
@@ -175,7 +176,7 @@
if (valueFind == result.end() || severityFind == result.end() ||
directionFind == result.end())
{
- std::cerr << "Malformed threshold in configuration\n";
+ lg2::error("Malformed threshold in configuration");
return;
}
unsigned int severity = std::visit(
@@ -194,8 +195,9 @@
[](const boost::system::error_code& ec) {
if (ec)
{
- std::cerr
- << "Error setting threshold " << ec << "\n";
+ lg2::error(
+ "Error setting threshold: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
}
},
entityManagerName, path, "org.freedesktop.DBus.Properties",
@@ -271,9 +273,11 @@
thresholdChanges.emplace_back(threshold, true, value);
if (++cHiTrue < assertLogCount)
{
- std::cerr << "Sensor " << sensor->name << " high threshold "
- << threshold.value << " assert: value " << value
- << " raw data " << sensor->rawValue << "\n";
+ lg2::info(
+ "Sensor name: {NAME}, high threshold: {THRESHOLD}, "
+ "assert value: {VALUE}, raw data: {RAW_DATA}",
+ "NAME", sensor->name, "THRESHOLD", threshold.value,
+ "VALUE", value, "RAW_DATA", sensor->rawValue);
}
}
else if (value < (threshold.value - threshold.hysteresis))
@@ -293,10 +297,11 @@
thresholdChanges.emplace_back(threshold, true, value);
if (++cLoTrue < assertLogCount)
{
- std::cerr
- << "Sensor " << sensor->name << " low threshold "
- << threshold.value << " assert: value " << sensor->value
- << " raw data " << sensor->rawValue << "\n";
+ lg2::info(
+ "Sensor name: {NAME}, low threshold: {THRESHOLD}, "
+ "assert value: {VALUE}, raw data: {RAW_DATA}",
+ "NAME", sensor->name, "THRESHOLD", threshold.value,
+ "VALUE", value, "RAW_DATA", sensor->rawValue);
}
}
else if (value > (threshold.value + threshold.hysteresis))
@@ -311,7 +316,7 @@
}
else
{
- std::cerr << "Error determining threshold direction\n";
+ lg2::error("Error determining threshold direction");
}
}
@@ -322,10 +327,12 @@
cDebugThrottle = 0;
if constexpr (debug)
{
- std::cerr << "checkThresholds: High T=" << cHiTrue
- << " F=" << cHiFalse << " M=" << cHiMidstate
- << ", Low T=" << cLoTrue << " F=" << cLoFalse
- << " M=" << cLoMidstate << "\n";
+ lg2::error("checkThresholds: High T= {HIGH_TRUE}, F= {HIGH_FALSE},"
+ " M= {HIGH_MIDSTATE}, Low T= {LOW_TRUE}, F= {LOW_FALSE},"
+ " M= {LOW_MIDSTATE}",
+ "HIGH_TRUE", cHiTrue, "HIGH_FALSE", cHiFalse,
+ "HIGH_MIDSTATE", cHiMidstate, "LOW_TRUE", cLoTrue,
+ "LOW_FALSE", cLoFalse, "LOW_MIDSTATE", cLoMidstate);
}
}
@@ -374,7 +381,8 @@
}
if (ec)
{
- std::cerr << "timer error: " << ec.message() << "\n";
+ lg2::error("timer error: '{ERROR_MESSAGE}'", "ERROR_MESSAGE",
+ ec.message());
return;
}
if (sensorPtr->readingStateGood())
@@ -451,14 +459,14 @@
if (!interface)
{
- std::cout << "trying to set uninitialized interface\n";
+ lg2::info("trying to set uninitialized interface");
return;
}
std::string property = Sensor::propertyAlarm(level, direction);
if (property.empty())
{
- std::cout << "Alarm property is empty \n";
+ lg2::info("Alarm property is empty");
return;
}
if (interface->set_property<bool, true>(property, assert))
@@ -475,8 +483,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr
- << "Failed to send thresholdAsserted signal with assertValue\n";
+ lg2::error(
+ "Failed to send thresholdAsserted signal with assertValue");
}
}
}
@@ -522,8 +530,8 @@
*val += offset;
if (debug)
{
- std::cout << "Threshold: " << attrPath << ": " << *val
- << "\n";
+ lg2::info("Threshold: '{PATH}': '{VALUE}'", "PATH",
+ attrPath, "VALUE", *val);
}
thresholdVector.emplace_back(level, direction, *val,
hysteresis);
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 2af6b50..202e394 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -24,6 +24,7 @@
#include <boost/asio/error.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/bus.hpp>
@@ -40,7 +41,6 @@
#include <filesystem>
#include <fstream>
#include <functional>
-#include <iostream>
#include <iterator>
#include <memory>
#include <optional>
@@ -143,9 +143,9 @@
}
catch (const std::bad_variant_access& err)
{
- std::cerr << err.what()
- << ":PermitList does not contain a list, wrong "
- "variant type.\n";
+ lg2::error(
+ "'{ERROR_MESSAGE}': PermitList does not contain a list, wrong variant type.",
+ "ERROR_MESSAGE", err.what());
}
}
return permitSet;
@@ -174,10 +174,12 @@
}
catch (const sdbusplus::exception_t& e)
{
- std::cerr << "While calling GetManagedObjects on service:"
- << entityManagerName << " exception name:" << e.name()
- << "and description:" << e.description()
- << " was thrown\n";
+ lg2::error(
+ "While calling GetManagedObjects on service: '{SERVICE_NAME}'"
+ " exception name: '{EXCEPTION_NAME}' and description: "
+ "'{EXCEPTION_DESCRIPTION}' was thrown",
+ "SERVICE_NAME", entityManagerName, "EXCEPTION_NAME", e.name(),
+ "EXCEPTION_DESCRIPTION", e.description());
return false;
}
}
@@ -370,8 +372,8 @@
// we commonly come up before power control, we'll capture the
// property change later
- std::cerr << "error getting power status " << ec.message()
- << "\n";
+ lg2::error("error getting power status: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
powerStatusOn = std::get<std::string>(state).ends_with(".Running");
@@ -402,8 +404,8 @@
}
// we commonly come up before power control, we'll capture the
// property change later
- std::cerr << "error getting post status " << ec.message()
- << "\n";
+ lg2::error("error getting post status: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
const auto& value = std::get<std::string>(state);
@@ -438,8 +440,9 @@
// we commonly come up before power control, we'll capture the
// property change later
- std::cerr << "error getting chassis power status "
- << ec.message() << "\n";
+ lg2::error(
+ "error getting chassis power status: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
chassisStatusOn =
@@ -494,7 +497,8 @@
}
if (ec)
{
- std::cerr << "Timer error " << ec.message() << "\n";
+ lg2::error("Timer error: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
powerStatusOn = true;
@@ -558,7 +562,8 @@
}
if (ec)
{
- std::cerr << "Timer error " << ec.message() << "\n";
+ lg2::error("Timer error: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
chassisStatusOn = true;
@@ -785,8 +790,7 @@
auto itr = propertyList.find("SpecialMode");
if (itr == propertyList.end())
{
- std::cerr << "error getting SpecialMode property "
- << "\n";
+ lg2::error("error getting SpecialMode property");
return;
}
auto* manufacturingModeStatus =
@@ -822,8 +826,9 @@
const std::variant<std::string>& getManufactMode) {
if (ec)
{
- std::cerr << "error getting SpecialMode status "
- << ec.message() << "\n";
+ lg2::error(
+ "error getting SpecialMode status: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
const auto* manufacturingModeStatus =
diff --git a/src/Utils.hpp b/src/Utils.hpp
index be96877..8cfdddd 100644
--- a/src/Utils.hpp
+++ b/src/Utils.hpp
@@ -5,6 +5,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/bus/match.hpp>
@@ -19,7 +20,6 @@
#include <cstdint>
#include <filesystem>
#include <functional>
-#include <iostream>
#include <memory>
#include <optional>
#include <regex>
@@ -162,7 +162,7 @@
auto it = data.find(key);
if (it == data.end())
{
- std::cerr << "Configuration missing " << key << "\n";
+ lg2::error("Configuration missing '{KEY}'", "KEY", key);
throw std::invalid_argument("Key Missing");
}
if constexpr (std::is_same_v<T, double>)
@@ -238,7 +238,7 @@
[name](const boost::system::error_code ec) {
if (ec)
{
- std::cerr << "Failed to set LED " << name << "\n";
+ lg2::error("Failed to set LED '{NAME}'", "NAME", name);
}
},
"xyz.openbmc_project.LED.GroupManager",
@@ -277,12 +277,13 @@
{
if (retries == 0U)
{
- std::cerr << "Error getting " << path
- << ": no retries left\n";
+ lg2::error("Error getting '{PATH}': no retries left",
+ "PATH", path);
return;
}
- std::cerr << "Error getting " << path << ": " << retries - 1
- << " retries left\n";
+ lg2::error(
+ "Error getting '{PATH}': '{RETRIES}' retries left",
+ "PATH", path, "RETRIES", retries - 1);
auto timer = std::make_shared<boost::asio::steady_timer>(
self->dbusConnection->get_io_context());
timer->expires_after(std::chrono::seconds(10));
@@ -290,7 +291,8 @@
retries](boost::system::error_code ec) {
if (ec)
{
- std::cerr << "Timer error!\n";
+ lg2::error("Timer error: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
self->getPath(path, interface, owner, retries - 1);
@@ -324,7 +326,8 @@
const GetSubTreeType& ret) {
if (ec)
{
- std::cerr << "Error calling mapper\n";
+ lg2::error("Error calling mapper: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
if (retries == 0U)
{
return;
@@ -336,7 +339,8 @@
retries](boost::system::error_code ec) {
if (ec)
{
- std::cerr << "Timer error!\n";
+ lg2::error("Timer error: '{ERROR_MESSAGE}'",
+ "ERROR_MESSAGE", ec.message());
return;
}
self->getConfiguration(interfaces, retries - 1);
@@ -401,7 +405,7 @@
auto findHyphen = deviceName.find('-');
if (findHyphen == std::string::npos)
{
- std::cerr << "found bad device " << deviceName << "\n";
+ lg2::error("found bad device '{NAME}'", "NAME", deviceName);
return false;
}
std::string busStr = deviceName.substr(0, findHyphen);
@@ -411,13 +415,13 @@
res = std::from_chars(&*busStr.begin(), &*busStr.end(), bus);
if (res.ec != std::errc{} || res.ptr != &*busStr.end())
{
- std::cerr << "Error finding bus for " << deviceName << "\n";
+ lg2::error("Error finding bus for '{NAME}'", "NAME", deviceName);
return false;
}
res = std::from_chars(&*addrStr.begin(), &*addrStr.end(), addr, 16);
if (res.ec != std::errc{} || res.ptr != &*addrStr.end())
{
- std::cerr << "Error finding addr for " << deviceName << "\n";
+ lg2::error("Error finding addr for '{NAME}'", "NAME", deviceName);
return false;
}
diff --git a/src/sensor.hpp b/src/sensor.hpp
index 2eab853..07d70ec 100644
--- a/src/sensor.hpp
+++ b/src/sensor.hpp
@@ -6,6 +6,7 @@
#include "Thresholds.hpp"
#include "Utils.hpp"
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/exception.hpp>
@@ -16,7 +17,6 @@
#include <cstddef>
#include <cstdlib>
#include <functional>
-#include <iostream>
#include <limits>
#include <memory>
#include <string>
@@ -136,7 +136,7 @@
size_t index = static_cast<size_t>(lev);
if (index >= thresholdInterfaces.size())
{
- std::cout << "Unknown threshold level \n";
+ lg2::info("Unknown threshold level");
return nullptr;
}
std::shared_ptr<sdbusplus::asio::dbus_interface> interface =
@@ -162,9 +162,10 @@
// Show constants if first reading (even if unsuccessful)
if ((inst.numCollectsGood == 0) && (inst.numCollectsMiss == 0))
{
- std::cerr << "Sensor " << name << ": Configuration min=" << minValue
- << ", max=" << maxValue << ", type=" << configInterface
- << ", path=" << configurationPath << "\n";
+ lg2::info(
+ "Sensor name: {NAME}, min: {MIN}, max: {MAX}, type: {TYPE}, path: {PATH}",
+ "NAME", name, "MIN", minValue, "MAX", maxValue, "TYPE",
+ configInterface, "PATH", configurationPath);
}
// Sensors can use "nan" to indicate unavailable reading
@@ -173,12 +174,12 @@
// Only show this if beginning a new streak
if (inst.numStreakMisses == 0)
{
- std::cerr << "Sensor " << name
- << ": Missing reading, Reading counts good="
- << inst.numCollectsGood
- << ", miss=" << inst.numCollectsMiss
- << ", Prior good streak=" << inst.numStreakGreats
- << "\n";
+ lg2::warning(
+ "Sensor name: {NAME}, Missing reading, Reading counts good= {NUM_COLLECTS_GOOD},"
+ " miss= {NUM_COLLECTS_MISS}, Prior good streak= {NUM_STREAK_GREATS}",
+ "NAME", name, "NUM_COLLECTS_GOOD", inst.numCollectsGood,
+ "NUM_COLLECTS_MISS", inst.numCollectsMiss,
+ "NUM_STREAK_GREATS", inst.numStreakGreats);
}
inst.numStreakGreats = 0;
@@ -191,18 +192,19 @@
// Only show this if beginning a new streak and not the first time
if ((inst.numStreakGreats == 0) && (inst.numCollectsGood != 0))
{
- std::cerr << "Sensor " << name
- << ": Recovered reading, Reading counts good="
- << inst.numCollectsGood
- << ", miss=" << inst.numCollectsMiss
- << ", Prior miss streak=" << inst.numStreakMisses << "\n";
+ lg2::info(
+ "Sensor name: {NAME}, Recovered reading, Reading counts good= {NUM_COLLECTS_GOOD},"
+ " miss= {NUM_COLLECTS_MISS}, Prior good streak= {NUM_STREAK_GREATS}",
+ "NAME", name, "NUM_COLLECTS_GOOD", inst.numCollectsGood,
+ "NUM_COLLECTS_MISS", inst.numCollectsMiss, "NUM_STREAK_GREATS",
+ inst.numStreakGreats);
}
// Initialize min/max if the first successful reading
if (inst.numCollectsGood == 0)
{
- std::cerr << "Sensor " << name << ": First reading=" << readValue
- << "\n";
+ lg2::info("Sensor name: {NAME}, First reading: {VALUE}", "NAME",
+ name, "VALUE", readValue);
inst.minCollected = readValue;
inst.maxCollected = readValue;
@@ -215,16 +217,16 @@
// Only provide subsequent output if new min/max established
if (readValue < inst.minCollected)
{
- std::cerr << "Sensor " << name << ": Lowest reading=" << readValue
- << "\n";
+ lg2::info("Sensor name: {NAME}, Lowest reading: {VALUE}", "NAME",
+ name, "VALUE", readValue);
inst.minCollected = readValue;
}
if (readValue > inst.maxCollected)
{
- std::cerr << "Sensor " << name << ": Highest reading=" << readValue
- << "\n";
+ lg2::info("Sensor name: {NAME}, Highest reading: {VALUE}", "NAME",
+ name, "VALUE", readValue);
inst.maxCollected = readValue;
}
@@ -293,7 +295,7 @@
if (!iface)
{
- std::cout << "trying to set uninitialized interface\n";
+ lg2::info("trying to set uninitialized interface");
continue;
}
@@ -331,7 +333,7 @@
}
if (!sensorInterface->initialize())
{
- std::cerr << "error initializing value interface\n";
+ lg2::error("error initializing value interface");
}
for (auto& thresIface : thresholdInterfaces)
@@ -340,7 +342,7 @@
{
if (!thresIface->initialize(true))
{
- std::cerr << "Error initializing threshold interface \n";
+ lg2::error("Error initializing threshold interface");
}
}
}
@@ -354,8 +356,8 @@
valueMutabilityInterface->register_property("Mutable", true);
if (!valueMutabilityInterface->initialize())
{
- std::cerr
- << "error initializing sensor value mutability interface\n";
+ lg2::error(
+ "error initializing sensor value mutability interface");
valueMutabilityInterface = nullptr;
}
}
@@ -478,7 +480,7 @@
errCount++;
if (errCount == errorThreshold)
{
- std::cerr << "Sensor " << name << " reading error!\n";
+ lg2::error("Sensor name: {NAME}, reading error!", "NAME", name);
markFunctional(false);
}
}
@@ -535,8 +537,8 @@
if (interface &&
!(interface->set_property(dbusPropertyName, newValue)))
{
- std::cerr << "error setting property " << dbusPropertyName
- << " to " << newValue << "\n";
+ lg2::error("error setting property '{NAME}' to '{VALUE}'",
+ "NAME", dbusPropertyName, "VALUE", newValue);
}
}
}
diff --git a/src/tests/test_Utils.cpp b/src/tests/test_Utils.cpp
index 3db6727..957a9e9 100644
--- a/src/tests/test_Utils.cpp
+++ b/src/tests/test_Utils.cpp
@@ -1,12 +1,13 @@
#include "Utils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <fstream>
-#include <iostream>
#include <new>
#include <string>
#include <vector>
@@ -78,7 +79,7 @@
p != std::filesystem::recursive_directory_iterator(); ++p)
{
std::string path = p->path().string();
- std::cerr << path << "\n";
+ lg2::info("{PATH}", "PATH", path);
if (p.depth() >= 6)
{
p.disable_recursion_pending();