sdr: Convert std::cerr to lg2
Change-Id: Ided5ac23f9b5a93e09928b324a5fc95ba689e874
Signed-off-by: Haicheng Zhang <zhanghch05@ieisystem.com>
diff --git a/dbus-sdr/meson.build b/dbus-sdr/meson.build
index a937485..31f7d2c 100644
--- a/dbus-sdr/meson.build
+++ b/dbus-sdr/meson.build
@@ -2,6 +2,7 @@
'sensorutils',
'sensorutils.cpp',
include_directories: root_inc,
+ dependencies: phosphor_logging_dep,
implicit_include_directories: false,
)
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 9f33dcd..90e2ebf 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -38,7 +38,6 @@
#include <cmath>
#include <cstring>
#include <format>
-#include <iostream>
#include <map>
#include <optional>
#include <stdexcept>
@@ -592,8 +591,9 @@
}
if constexpr (debug)
{
- std::cerr << "VR sensor " << sensor::parseSdrIdFromPath(path)
- << " mode is: [" << index << "] " << mode << std::endl;
+ lg2::error("VR sensor {PATH} mode is: [{INDEX}] {MODE}", "PATH",
+ sensor::parseSdrIdFromPath(path), "INDEX", index, "MODE",
+ mode);
}
return true;
}
@@ -1032,15 +1032,14 @@
{
// This is the first reading, show the coefficients
double step = (max - min) / 255.0;
- std::cerr
- << "IPMI sensor "
- << details::sdrStatsTable.getName((ctx->lun << 8) | sensnum)
- << ": Range min=" << min << " max=" << max << ", step=" << step
- << ", Coefficients mValue=" << static_cast<int>(mValue)
- << " rExp=" << static_cast<int>(rExp)
- << " bValue=" << static_cast<int>(bValue)
- << " bExp=" << static_cast<int>(bExp)
- << " bSigned=" << static_cast<int>(bSigned) << "\n";
+ lg2::error(
+ "IPMI sensor {NAME}: Range min={MIN} max={MAX}, step={STEP}, "
+ "Coefficients mValue={MVALUE} rExp={REXP} bValue={BVALUE} "
+ "bExp={BEXP} bSigned={BSIGNED}",
+ "NAME",
+ details::sdrStatsTable.getName((ctx->lun << 8) | sensnum),
+ "MIN", min, "MAX", max, "STEP", step, "MVALUE", mValue, "REXP",
+ rExp, "BVALUE", bValue, "BEXP", bExp, "BSIGNED", bSigned);
}
}
diff --git a/dbus-sdr/sensorutils.cpp b/dbus-sdr/sensorutils.cpp
index 8c6952b..fee9d50 100644
--- a/dbus-sdr/sensorutils.cpp
+++ b/dbus-sdr/sensorutils.cpp
@@ -16,9 +16,10 @@
#include "dbus-sdr/sensorutils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <algorithm>
#include <cmath>
-#include <iostream>
namespace ipmi
{
@@ -153,19 +154,19 @@
{
if (!(std::isfinite(min)))
{
- std::cerr << "getSensorAttributes: Min value is unusable\n";
+ lg2::error("getSensorAttributes: Min value is unusable");
return false;
}
if (!(std::isfinite(max)))
{
- std::cerr << "getSensorAttributes: Max value is unusable\n";
+ lg2::error("getSensorAttributes: Max value is unusable");
return false;
}
// Because NAN has already been tested for, this comparison works
if (max <= min)
{
- std::cerr << "getSensorAttributes: Max must be greater than min\n";
+ lg2::error("getSensorAttributes: Max must be greater than min");
return false;
}
@@ -210,8 +211,10 @@
// Step 2: Constrain M, and set rExp accordingly
if (!(scaleFloatExp(dM, rExp)))
{
- std::cerr << "getSensorAttributes: Multiplier range exceeds scale (M="
- << dM << ", rExp=" << (int)rExp << ")\n";
+ lg2::error(
+ "getSensorAttributes: Multiplier range exceeds scale (M={DM}, "
+ "rExp={REXP})",
+ "DM", dM, "REXP", rExp);
return false;
}
@@ -222,7 +225,7 @@
// The multiplier can not be zero, for obvious reasons
if (mValue == 0)
{
- std::cerr << "getSensorAttributes: Multiplier range below scale\n";
+ lg2::error("getSensorAttributes: Multiplier range below scale");
return false;
}
@@ -240,9 +243,10 @@
// Step 4: Constrain B, and set bExp accordingly
if (!(scaleFloatExp(dB, bExp)))
{
- std::cerr << "getSensorAttributes: Offset (B=" << dB << ", bExp="
- << (int)bExp << ") exceeds multiplier scale (M=" << dM
- << ", rExp=" << (int)rExp << ")\n";
+ lg2::error(
+ "getSensorAttributes: Offset range exceeds scale (B={DB}, "
+ "bExp={BEXP}) exceeds multiplier scale (M={DM}, rExp={REXP})",
+ "DB", dB, "BEXP", bExp, "DM", dM, "REXP", rExp);
return false;
}
diff --git a/dbus-sdr/storagecommands.cpp b/dbus-sdr/storagecommands.cpp
index 74ac3dd..856699b 100644
--- a/dbus-sdr/storagecommands.cpp
+++ b/dbus-sdr/storagecommands.cpp
@@ -34,7 +34,6 @@
#include <filesystem>
#include <fstream>
#include <functional>
-#include <iostream>
#include <optional>
#include <stdexcept>
#include <string_view>
@@ -1047,7 +1046,7 @@
}
catch (const std::invalid_argument&)
{
- std::cerr << "Invalid Generator ID\n";
+ lg2::error("Invalid Generator ID");
}
// Get the sensor type, sensor number, and event type for the sensor
@@ -1073,7 +1072,7 @@
}
catch (const std::invalid_argument&)
{
- std::cerr << "Invalid Event Direction\n";
+ lg2::error("Invalid Event Direction");
}
}
@@ -1188,7 +1187,7 @@
"xyz.openbmc_project.Logging.IPMI", "Clear");
if (ec)
{
- std::cerr << "error in clear SEL: " << ec.message() << std::endl;
+ lg2::error("error in clear SEL: {MSG}", "MSG", ec.message());
return ipmi::responseUnspecifiedError();
}
diff --git a/include/dbus-sdr/sdrutils.hpp b/include/dbus-sdr/sdrutils.hpp
index dcbaf59..9d36a50 100644
--- a/include/dbus-sdr/sdrutils.hpp
+++ b/include/dbus-sdr/sdrutils.hpp
@@ -102,11 +102,11 @@
// Only show this if beginning a new streak
if (numStreakMiss == 0)
{
- std::cerr << "IPMI sensor " << sensorName
- << ": Missing reading, byte=" << raw
- << ", Reading counts good=" << numReadings
- << " miss=" << numMissings
- << ", Prior good streak=" << numStreakRead << "\n";
+ lg2::error(
+ "IPMI sensor {NAME}: Missing reading, byte={BYTE}, Reading "
+ "counts good={GOOD} miss={MISS}, Prior good streak={STREAK}",
+ "NAME", sensorName, "BYTE", raw, "GOOD", numReadings,
+ "MISS", numMissings, "STREAK", numStreakRead);
}
numStreakRead = 0;
@@ -119,19 +119,20 @@
// Only show this if beginning a new streak and not the first time
if ((numStreakRead == 0) && (numReadings != 0))
{
- std::cerr << "IPMI sensor " << sensorName
- << ": Recovered reading, value=" << reading << " byte="
- << raw << ", Reading counts good=" << numReadings
- << " miss=" << numMissings
- << ", Prior miss streak=" << numStreakMiss << "\n";
+ lg2::error(
+ "IPMI sensor {NAME}: Recovered reading, value={VALUE} byte={BYTE}"
+ ", Reading counts good={GOOD} miss={MISS}, Prior miss "
+ "streak={STREAK}",
+ "NAME", sensorName, "VALUE", reading, "BYTE", raw, "GOOD",
+ numReadings, "MISS", numMissings, "STREAK", numStreakMiss);
}
// Initialize min/max if the first successful reading
if (numReadings == 0)
{
- std::cerr << "IPMI sensor " << sensorName
- << ": First reading, value=" << reading << " byte=" << raw
- << "\n";
+ lg2::error(
+ "IPMI sensor {NAME}: First reading, value={VALUE} byte={BYTE}",
+ "NAME", sensorName, "VALUE", reading, "BYTE", raw);
minValue = reading;
maxValue = reading;
@@ -144,18 +145,18 @@
// Only provide subsequent output if new min/max established
if (reading < minValue)
{
- std::cerr << "IPMI sensor " << sensorName
- << ": Lowest reading, value=" << reading
- << " byte=" << raw << "\n";
+ lg2::error(
+ "IPMI sensor {NAME}: Lowest reading, value={VALUE} byte={BYTE}",
+ "NAME", sensorName, "VALUE", reading, "BYTE", raw);
minValue = reading;
}
if (reading > maxValue)
{
- std::cerr << "IPMI sensor " << sensorName
- << ": Highest reading, value=" << reading
- << " byte=" << raw << "\n";
+ lg2::error(
+ "IPMI sensor {NAME}: Highest reading, value={VALUE} byte={BYTE}",
+ "NAME", sensorName, "VALUE", reading, "BYTE", raw);
maxValue = reading;
}