logging: switch to lg2
After switching to C++20, it is recommended to use `phosphor::lg2`
to format log, and the correct `CODE_LINE` and `CODE_FUNC` values
can be used in log tracking.
Change-Id: Ia8e566b3e4c667bb9dd15e9ea224b93faf6c0557
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/src/iei_oem.cpp b/src/iei_oem.cpp
index a403722..bffab0f 100644
--- a/src/iei_oem.cpp
+++ b/src/iei_oem.cpp
@@ -7,7 +7,7 @@
#include <ipmid/api.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <optional>
@@ -32,7 +32,6 @@
#define UNUSED(x) (void)(x)
-using namespace phosphor::logging;
using namespace iei;
static void registerOEMFunctions() __attribute__((constructor));
@@ -159,7 +158,8 @@
auto deviceType = info->deviceType;
if (deviceType != 0x05)
{
- log<level::WARNING>("Device type not supported yet");
+ lg2::info("Device type ({DEVICE_TYPE}) not supported yet",
+ "DEVICE_TYPE", deviceType);
return IPMI_CC_UNSPECIFIED_ERROR;
}
diff --git a/src/utils.cpp b/src/utils.cpp
index f745a26..60117bb 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,11 +1,9 @@
#include "utils.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
-using namespace phosphor::logging;
-
namespace utils
{
@@ -50,7 +48,7 @@
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- log<level::ERR>("Error reading mapper response");
+ lg2::error("Error reading mapper response");
throw std::runtime_error("Error reading mapper response");
}
std::vector<std::string> ret;
@@ -62,8 +60,9 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- log<level::ERR>("GetObject call failed", entry("PATH=%s", path),
- entry("INTERFACE=%s", interface));
+ lg2::error(
+ "GetObject call failed, path: {PATH}, interface: {INTERFACE}",
+ "PATH", path, "INTERFACE", interface);
throw std::runtime_error("GetObject call failed");
}
}
@@ -84,9 +83,9 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- log<level::ERR>("GetProperty call failed", entry("PATH=%s", path),
- entry("INTERFACE=%s", interface),
- entry("PROPERTY=%s", propertyName));
+ lg2::error(
+ "GetProperty call failed, path: {PATH}, interface: {INTERFACE}, property: {PROPERTY}",
+ "PATH", path, "INTERFACE", interface, "PROPERTY", propertyName);
throw std::runtime_error("GetProperty call failed");
}
}
@@ -104,9 +103,9 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- log<level::ERR>("SetProperty call failed", entry("PATH=%s", path),
- entry("INTERFACE=%s", interface),
- entry("PROPERTY=%s", propertyName));
+ lg2::error(
+ "SetProperty call failed, path: {PATH}, interface: {INTERFACE}, property: {PROPERTY}",
+ "PATH", path, "INTERFACE", interface, "PROPERTY", propertyName);
throw std::runtime_error("SetProperty call failed");
}
}