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: I151fc489a93ec7f513411aea2f0b61829bc808f6
diff --git a/snmp_conf_manager.cpp b/snmp_conf_manager.cpp
index d77f8b7..4ddace1 100644
--- a/snmp_conf_manager.cpp
+++ b/snmp_conf_manager.cpp
@@ -9,7 +9,7 @@
#include <arpa/inet.h>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <filesystem>
@@ -44,8 +44,7 @@
}
catch (const InternalFailure& e)
{
- log<level::ERR>("Not a valid address"),
- entry("ADDRESS=%s", address.c_str());
+ lg2::error("{ADDRESS} is not a valid address", "ADDRESS", address);
elog<InvalidArgument>(Argument::ARGUMENT_NAME("Address"),
Argument::ARGUMENT_VALUE(address.c_str()));
}
@@ -70,7 +69,7 @@
{
if (address.empty())
{
- log<level::ERR>("Invalid address");
+ lg2::error("{ADDRESS} is not a valid address", "ADDRESS", address);
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ADDRESS"),
Argument::ARGUMENT_VALUE(address.c_str()));
}
@@ -80,7 +79,7 @@
if (val.second.get()->address() == address &&
val.second.get()->port() == port)
{
- log<level::ERR>("Client already exist");
+ lg2::error("Client already exist");
// TODO Add the error(Object already exist) in the D-Bus interface
// then make the change here,meanwhile send the Internal Failure.
elog<InvalidArgument>(
@@ -95,8 +94,7 @@
auto it = clients.find(id);
if (it == clients.end())
{
- log<level::ERR>("Unable to delete the snmp client.",
- entry("ID=%d", id));
+ lg2::error("Unable to delete the snmp client: {ID}", "ID", id);
return;
}
@@ -109,15 +107,13 @@
{
if (!fs::remove(fileName, ec))
{
- log<level::ERR>("Unable to delete the file",
- entry("FILE=%s", fileName.c_str()),
- entry("ERROR=%d", ec.value()));
+ lg2::error("Unable to delete {FILE}: {EC}", "FILE", fileName, "EC",
+ ec.value());
}
}
else
{
- log<level::ERR>("File doesn't exist",
- entry("FILE=%s", fileName.c_str()));
+ lg2::error("{FILE} doesn't exist", "FILE", fileName);
}
// remove the D-Bus Object.
this->clients.erase(it);