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.
Tested: built biosConfigManager successfully.
journalctl -o json-pretty SYSLOG_IDENTIFIER=biosconfig-manager
{
"_TRANSPORT" : "journal",
"_PID" : "244",
"__MONOTONIC_TIMESTAMP" : "513878067",
"_SYSTEMD_SLICE" : "system.slice",
"CODE_LINE" : "123",
"_SOURCE_REALTIME_TIMESTAMP" : "513877941",
"_HOSTNAME" : "fp5280g2",
"_CAP_EFFECTIVE" : "1ffffffffff",
"_BOOT_ID" : "40382c3612f54e1a96a6ecf41fe6b38e",
"SYSLOG_IDENTIFIER" : "biosconfig-manager",
"_CMDLINE" : "/usr/bin/biosconfig-manager",
"_EXE" : "/usr/bin/biosconfig-manager",
"LOG2_FMTMSG" : "BIOS attribute not found in the BaseBIOSTable",
"_SYSTEMD_UNIT" : "xyz.openbmc_project.biosconfig_manager.service",
"MESSAGE" : "BIOS attribute not found in the BaseBIOSTable",
"PRIORITY" : "3",
"CODE_FILE" : "../biosconfig-manager/src/manager.cpp",
"CODE_FUNC" : "virtual bios_config::Manager::PendingAttributes
bios_config::Manager::pendingAttributes
(bios_config::Manager::PendingAttributes)"
...
}
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I274d61827279b10ba3fe9d61404ce8b654ccdd9e
diff --git a/src/manager_serialize.cpp b/src/manager_serialize.cpp
index 0756006..18163b7 100644
--- a/src/manager_serialize.cpp
+++ b/src/manager_serialize.cpp
@@ -7,15 +7,13 @@
#include <cereal/types/tuple.hpp>
#include <cereal/types/variant.hpp>
#include <cereal/types/vector.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <fstream>
namespace bios_config
{
-using namespace phosphor::logging;
-
/** @brief Function required by Cereal to perform serialization.
*
* @tparam Archive - Cereal archive type (binary in this case).
@@ -77,13 +75,13 @@
}
catch (cereal::Exception& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to serialize: {ERROR}", "ERROR", e);
fs::remove(path);
return false;
}
catch (const std::length_error& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to serialize: {ERROR}", "ERROR", e);
fs::remove(path);
return false;
}