convert dcmihandler.cpp to use lg2
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: Icc2fa6cbb16e1b7f0ed07b2871bd39bfefceafe0
diff --git a/dcmihandler.cpp b/dcmihandler.cpp
index e45ea3f..77fe6c5 100644
--- a/dcmihandler.cpp
+++ b/dcmihandler.cpp
@@ -8,7 +8,7 @@
#include <ipmid/utils.hpp>
#include <nlohmann/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
@@ -76,14 +76,14 @@
std::ifstream jsonFile(configFile);
if (!jsonFile.is_open())
{
- log<level::ERR>("Temperature readings JSON file not found");
+ lg2::error("Temperature readings JSON file not found");
elog<InternalFailure>();
}
auto data = nlohmann::json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- log<level::ERR>("Temperature readings JSON parser failure");
+ lg2::error("Temperature readings JSON parser failure");
elog<InternalFailure>();
}
@@ -118,8 +118,7 @@
powerCapProp, pcap);
if (ec.value())
{
- log<level::ERR>("Error in getPcap prop",
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Error in getPcap prop: {ERROR}", "ERROR", ec.message());
elog<InternalFailure>();
return std::nullopt;
}
@@ -140,7 +139,7 @@
powerCapEnableProp, pcapEnabled);
if (ec.value())
{
- log<level::ERR>("Error in getPcap prop");
+ lg2::error("Error in getPcap prop");
elog<InternalFailure>();
return std::nullopt;
}
@@ -161,8 +160,7 @@
powerCapProp, powerCap);
if (ec.value())
{
- log<level::ERR>("Error in setPcap property",
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Error in setPcap property: {ERROR}", "ERROR", ec.message());
elog<InternalFailure>();
return false;
}
@@ -183,8 +181,8 @@
powerCapEnableProp, enabled);
if (ec.value())
{
- log<level::ERR>("Error in setPcapEnabled property",
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Error in setPcapEnabled property: {ERROR}", "ERROR",
+ ec.message());
elog<InternalFailure>();
return false;
}
@@ -209,8 +207,8 @@
assetTag);
if (ec.value())
{
- log<level::ERR>("Error in reading asset tag",
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Error in reading asset tag: {ERROR}", "ERROR",
+ ec.message());
elog<InternalFailure>();
return std::nullopt;
}
@@ -235,8 +233,8 @@
assetTag);
if (ec.value())
{
- log<level::ERR>("Error in writing asset tag",
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Error in writing asset tag: {ERROR}", "ERROR",
+ ec.message());
elog<InternalFailure>();
return false;
}
@@ -257,7 +255,7 @@
networkConfigIntf, hostNameProp, hostname);
if (ec.value())
{
- log<level::ERR>("Error fetching hostname");
+ lg2::error("Error fetching hostname");
elog<InternalFailure>();
return std::nullopt;
}
@@ -405,7 +403,7 @@
{
if (!dcmi::isDCMIPowerMgmtSupported())
{
- log<level::ERR>("DCMI Power management is unsupported!");
+ lg2::error("DCMI Power management is unsupported!");
return ipmi::responseInvalidCommand();
}
@@ -422,7 +420,7 @@
return ipmi::responseUnspecifiedError();
}
- log<level::INFO>("Set Power Cap", entry("POWERCAP=%u", powerLimit));
+ lg2::info("Set Power Cap: {POWERCAP}", "POWERCAP", powerLimit);
return ipmi::responseSuccess();
}
@@ -432,7 +430,7 @@
{
if (!dcmi::isDCMIPowerMgmtSupported())
{
- log<level::ERR>("DCMI Power management is unsupported!");
+ lg2::error("DCMI Power management is unsupported!");
return ipmi::responseInvalidCommand();
}
if (reserved1 || reserved2)
@@ -445,8 +443,8 @@
return ipmi::responseUnspecifiedError();
}
- log<level::INFO>("Set Power Cap Enable",
- entry("POWERCAPENABLE=%u", static_cast<uint8_t>(enabled)));
+ lg2::info("Set Power Cap Enable: {POWERCAPENABLE}", "POWERCAPENABLE",
+ enabled);
return ipmi::responseSuccess();
}
@@ -640,14 +638,14 @@
std::ifstream dcmiCapFile(dcmi::gDCMICapabilitiesConfig);
if (!dcmiCapFile.is_open())
{
- log<level::ERR>("DCMI Capabilities file not found");
+ lg2::error("DCMI Capabilities file not found");
return ipmi::responseUnspecifiedError();
}
auto data = nlohmann::json::parse(dcmiCapFile, nullptr, false);
if (data.is_discarded())
{
- log<level::ERR>("DCMI Capabilities JSON parser failure");
+ lg2::error("DCMI Capabilities JSON parser failure");
return ipmi::responseUnspecifiedError();
}
@@ -728,7 +726,7 @@
}
default:
{
- log<level::ERR>("Invalid input parameter");
+ lg2::error("Invalid input parameter");
return ipmi::responseInvalidFieldRequest();
}
}
@@ -845,14 +843,14 @@
auto it = dcmi::entityIdToName.find(entityId);
if (it == dcmi::entityIdToName.end())
{
- log<level::ERR>("Unknown Entity ID", entry("ENTITY_ID=%d", entityId));
+ lg2::error("Unknown Entity ID: {ENTITY_ID}", "ENTITY_ID", entityId);
return ipmi::responseInvalidFieldRequest();
}
if (sensorType != dcmi::temperatureSensorType)
{
- log<level::ERR>("Invalid sensor type",
- entry("SENSOR_TYPE=%d", sensorType));
+ lg2::error("Invalid sensor type: {SENSOR_TYPE}", "SENSOR_TYPE",
+ sensorType);
return ipmi::responseInvalidFieldRequest();
}
@@ -992,24 +990,26 @@
std::string objectPath;
if (!sensorFile.is_open())
{
- log<level::ERR>("Power reading configuration file not found",
- entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR));
+ lg2::error(
+ "Power reading configuration file not found: {POWER_SENSOR_FILE}",
+ "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR});
return std::nullopt;
}
auto data = nlohmann::json::parse(sensorFile, nullptr, false);
if (data.is_discarded())
{
- log<level::ERR>("Error in parsing configuration file",
- entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR));
+ lg2::error("Error in parsing configuration file: {POWER_SENSOR_FILE}",
+ "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR});
return std::nullopt;
}
objectPath = data.value("path", "");
if (objectPath.empty())
{
- log<level::ERR>("Power sensor D-Bus object path is empty",
- entry("POWER_SENSOR_FILE=%s", POWER_READING_SENSOR));
+ lg2::error(
+ "Power sensor D-Bus object path is empty: {POWER_SENSOR_FILE}",
+ "POWER_SENSOR_FILE", std::string_view{POWER_READING_SENSOR});
return std::nullopt;
}
@@ -1019,9 +1019,10 @@
objectPath, service);
if (ec.value())
{
- log<level::ERR>("Failed to fetch service for D-Bus object",
- entry("OBJECT_PATH=%s", objectPath.c_str()),
- entry("INTERFACE=%s", dcmi::sensorValueIntf));
+ lg2::error("Failed to fetch service for D-Bus object, "
+ "object path: {OBJECT_PATH}, interface: {INTERFACE}",
+ "OBJECT_PATH", objectPath, "INTERFACE",
+ dcmi::sensorValueIntf);
return std::nullopt;
}
@@ -1031,9 +1032,10 @@
dcmi::sensorValueProp, value);
if (ec.value())
{
- log<level::ERR>("Failure to read power value from D-Bus object",
- entry("OBJECT_PATH=%s", objectPath.c_str()),
- entry("INTERFACE=%s", dcmi::sensorValueIntf));
+ lg2::error("Failed to read power value from D-Bus object, "
+ "object path: {OBJECT_PATH}, interface: {INTERFACE}",
+ "OBJECT_PATH", objectPath, "INTERFACE",
+ dcmi::sensorValueIntf);
return std::nullopt;
}
auto power = static_cast<uint16_t>(value);
@@ -1055,7 +1057,7 @@
{
if (!dcmi::isDCMIPowerMgmtSupported())
{
- log<level::ERR>("DCMI Power management is unsupported!");
+ lg2::error("DCMI Power management is unsupported!");
return ipmi::responseInvalidCommand();
}
if (reserved)
@@ -1149,14 +1151,14 @@
auto it = dcmi::entityIdToName.find(entityId);
if (it == dcmi::entityIdToName.end())
{
- log<level::ERR>("Unknown Entity ID", entry("ENTITY_ID=%d", entityId));
+ lg2::error("Unknown Entity ID: {ENTITY_ID}", "ENTITY_ID", entityId);
return ipmi::responseInvalidFieldRequest();
}
if (sensorType != dcmi::temperatureSensorType)
{
- log<level::ERR>("Invalid sensor type",
- entry("SENSOR_TYPE=%d", sensorType));
+ lg2::error("Invalid sensor type: {SENSOR_TYPE}", "SENSOR_TYPE",
+ sensorType);
return ipmi::responseInvalidFieldRequest();
}