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.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I4fe8f4dec90e5062096168e05947b6d9bc355bb2
diff --git a/gpio-util/gpio.cpp b/gpio-util/gpio.cpp
index 0b671a8..0e825b9 100644
--- a/gpio-util/gpio.cpp
+++ b/gpio-util/gpio.cpp
@@ -18,17 +18,16 @@
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <cassert>
+#include <cstring>
namespace phosphor
{
namespace gpio
{
-using namespace phosphor::logging;
-
void GPIO::set(Value value)
{
assert(direction == Direction::output);
@@ -41,8 +40,7 @@
auto rc = ioctl(lineFD(), GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
if (rc == -1)
{
- auto e = errno;
- log<level::ERR>("Failed SET_LINE_VALUES ioctl", entry("ERRNO=%d", e));
+ lg2::error("Failed SET_LINE_VALUES ioctl: {ERRNO}", "ERRNO", errno);
throw std::runtime_error("Failed SET_LINE_VALUES ioctl");
}
}
@@ -58,10 +56,8 @@
FileDescriptor fd{open(device.c_str(), 0)};
if (fd() == -1)
{
- auto e = errno;
- log<level::ERR>("Failed opening GPIO device",
- entry("DEVICE=%s", device.c_str()),
- entry("ERRNO=%d", e));
+ lg2::error("Failed opening {DEVICE}: {ERRNO}", "DEVICE", device,
+ "ERRNO", errno);
throw std::runtime_error("Failed opening GPIO device");
}
@@ -85,9 +81,8 @@
auto rc = ioctl(fd(), GPIO_GET_LINEHANDLE_IOCTL, &request);
if (rc == -1)
{
- auto e = errno;
- log<level::ERR>("Failed GET_LINEHANDLE ioctl", entry("GPIO=%d", gpio),
- entry("ERRNO=%d", e));
+ lg2::error("Failed GET_LINEHANDLE ioctl {GPIO}: {ERRNO}", "GPIO", gpio,
+ "ERRNO", errno);
throw std::runtime_error("Failed GET_LINEHANDLE ioctl");
}