hwmon-temp: Convert logging to lg2
Change-Id: Ie4f9a2b48a42ae060cc7f89167ae913af17a9f38
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/src/hwmon-temp/HwmonTempMain.cpp b/src/hwmon-temp/HwmonTempMain.cpp
index 1ec199f..0074900 100644
--- a/src/hwmon-temp/HwmonTempMain.cpp
+++ b/src/hwmon-temp/HwmonTempMain.cpp
@@ -26,6 +26,8 @@
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
+#include <phosphor-logging/lg2.hpp>
+#include <phosphor-logging/lg2/flags.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/bus.hpp>
@@ -40,8 +42,6 @@
#include <cstdint>
#include <filesystem>
#include <functional>
-#include <ios>
-#include <iostream>
#include <memory>
#include <optional>
#include <regex>
@@ -223,7 +223,7 @@
if ((std::get_if<uint64_t>(&busCfg->second) == nullptr) ||
(std::get_if<uint64_t>(&addrCfg->second) == nullptr))
{
- std::cerr << path.str << " Bus or Address invalid\n";
+ lg2::error("'{PATH}' Bus or Address invalid", "PATH", path.str);
continue;
}
@@ -253,9 +253,10 @@
auto [it, inserted] = configMap.emplace(key, std::move(val));
if (!inserted)
{
- std::cerr << path.str << ": ignoring duplicate entry for {"
- << key.bus << ", 0x" << std::hex << key.addr
- << std::dec << "}\n";
+ lg2::error(
+ "'{PATH}': ignoring duplicate entry for '{BUS}', '{ADDR}'",
+ "PATH", path.str, "BUS", key.bus, "ADDR", lg2::hex,
+ key.addr);
}
}
}
@@ -315,8 +316,8 @@
device = std::filesystem::canonical(directory, ec);
if (ec)
{
- std::cerr << "Fail to find device in path [" << pathStr
- << "]\n";
+ lg2::error("Fail to find device in '{PATH}'", "PATH",
+ pathStr);
continue;
}
deviceName = device.parent_path().stem();
@@ -327,8 +328,8 @@
std::filesystem::canonical(directory / "device", ec);
if (ec)
{
- std::cerr << "Fail to find device in path [" << pathStr
- << "]\n";
+ lg2::error("Fail to find device in '{PATH}'", "PATH",
+ pathStr);
continue;
}
deviceName = device.stem();
@@ -389,8 +390,9 @@
if (findSensorName == baseConfigMap.end())
{
- std::cerr << "could not determine configuration name for "
- << deviceName << "\n";
+ lg2::error(
+ "could not determine configuration name for '{NAME}'",
+ "NAME", deviceName);
continue;
}
std::string sensorName =
@@ -423,8 +425,9 @@
if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
nullptr, &index))
{
- std::cerr << "error populating thresholds for "
- << sensorName << " index " << index << "\n";
+ lg2::error("error populating thresholds for "
+ "'{NAME}', index: '{INDEX}'",
+ "NAME", sensorName, "INDEX", index);
}
float pollRate = getPollRate(baseConfigMap, pollRateDefault);
@@ -495,9 +498,9 @@
if (!parseThresholdsFromConfig(sensorData, thresholds,
nullptr, &index))
{
- std::cerr
- << "error populating thresholds for "
- << sensorName << " index " << index << "\n";
+ lg2::error("error populating thresholds for "
+ "'{NAME}', index: '{INDEX}'",
+ "NAME", sensorName, "INDEX", index);
}
auto& sensor = sensors[sensorName];
@@ -546,7 +549,7 @@
{
if (message.is_method_error())
{
- std::cerr << "interfacesRemoved callback method error\n";
+ lg2::error("interfacesRemoved callback method error");
return;
}
@@ -624,7 +627,7 @@
[&](sdbusplus::message_t& message) {
if (message.is_method_error())
{
- std::cerr << "callback method error\n";
+ lg2::error("callback method error");
return;
}
sensorsChanged->insert(message.get_path());
@@ -639,7 +642,7 @@
}
if (ec)
{
- std::cerr << "timer error\n";
+ lg2::error("timer error");
return;
}
createSensors(io, objectServer, sensors, systemBus,
diff --git a/src/hwmon-temp/HwmonTempSensor.cpp b/src/hwmon-temp/HwmonTempSensor.cpp
index 9ebd6c9..2957b09 100644
--- a/src/hwmon-temp/HwmonTempSensor.cpp
+++ b/src/hwmon-temp/HwmonTempSensor.cpp
@@ -26,13 +26,13 @@
#include <boost/asio/error.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/random_access_file.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <charconv>
#include <chrono>
#include <cstddef>
-#include <iostream>
#include <limits>
#include <memory>
#include <string>
@@ -177,8 +177,8 @@
if ((err == boost::system::errc::bad_file_descriptor) ||
(err == boost::asio::error::misc_errors::not_found))
{
- std::cerr << "Hwmon temp sensor " << name << " removed " << path
- << "\n";
+ lg2::error("Hwmon temp sensor '{NAME}' removed '{PATH}'", "NAME", name,
+ "PATH", path);
return; // we're being destroyed
}