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: I4aabaafe997e13c10d655a83a9ef0071ad11126e
diff --git a/main.cpp b/main.cpp
index fc9a28c..b66c6f5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -19,14 +19,12 @@
#include <unistd.h>
#include <CLI/CLI.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <user_channel/channel_layer.hpp>
#include <tuple>
-using namespace phosphor::logging;
-
static auto io = std::make_shared<boost::asio::io_context>();
std::shared_ptr<boost::asio::io_context> getIo()
{
@@ -63,9 +61,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Requested channel name is not a valid channel name",
- entry("ERROR=%s", e.what()),
- entry("CHANNEL=%s", channel.c_str()));
+ lg2::error("Requested {NAME} is not a valid channel name: {ERROR}",
+ "NAME", channel, "ERROR", e);
}
}
EInterfaceIndex getInterfaceIndex(void)
@@ -88,8 +85,8 @@
auto rc = sd_bus_default_system(&bus);
if (rc < 0)
{
- log<level::ERR>("Failed to connect to system bus",
- entry("ERROR=%s", strerror(-rc)));
+ lg2::error("Failed to connect to system bus: {ERROR}", "ERROR",
+ strerror(-rc));
return rc;
}
sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);