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.cpp b/src/manager.cpp
index 14654be..0cb4259 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -21,6 +21,7 @@
#include <boost/asio.hpp>
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
@@ -119,8 +120,7 @@
// BIOS attribute not found in the BaseBIOSTable
if (iter == biosTable.end())
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "BIOS attribute not found in the BaseBIOSTable");
+ lg2::error("BIOS attribute not found in the BaseBIOSTable");
throw AttributeNotFound();
}
@@ -128,8 +128,7 @@
std::get<static_cast<uint8_t>(Index::attributeType)>(iter->second);
if (attributeType != std::get<0>(pair.second))
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "attributeType is not same with bios base table");
+ lg2::error("attributeType is not same with bios base table");
throw InvalidArgument();
}
@@ -139,8 +138,7 @@
// For enumeration the expected variant types is Enumeration
if (std::get<1>(pair.second).index() == 0)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Enumeration property value is not enum");
+ lg2::error("Enumeration property value is not enum");
throw InvalidArgument();
}
@@ -163,8 +161,7 @@
if (!found)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "No valid attribute");
+ lg2::error("No valid attribute");
throw InvalidArgument();
}
}
@@ -174,8 +171,7 @@
// For enumeration the expected variant types is std::string
if (std::get<1>(pair.second).index() == 0)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "String property value is not string");
+ lg2::error("String property value is not string");
throw InvalidArgument();
}
@@ -196,10 +192,8 @@
if (optionsIterator == options.end())
{
- std::string error =
- attrValue + " is not a valid value for " + pair.first;
- phosphor::logging::log<phosphor::logging::level::ERR>(
- error.c_str());
+ lg2::error("{ATTRVALUE} is not a valid value for {NAME}",
+ "ATTRVALUE", attrValue, "NAME", pair.first);
throw InvalidArgument();
}
}
@@ -209,8 +203,7 @@
// For enumeration the expected variant types is Integer
if (std::get<1>(pair.second).index() == 1)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Enumeration property value is not int");
+ lg2::error("Enumeration property value is not int");
throw InvalidArgument();
}
@@ -241,16 +234,16 @@
if ((attrValue < lowerBound) || (attrValue > upperBound))
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Integer, bound is invalid");
+ lg2::error("Integer, bound is invalid");
throw InvalidArgument();
}
if (((std::abs(attrValue - lowerBound)) % scalarIncrement) != 0)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "((std::abs(attrValue - lowerBound)) % scalarIncrement) != "
- "0");
+ lg2::error(
+ "((std::abs({ATTR_VALUE} - {LOWER_BOUND})) % {SCALAR_INCREMENT}) != 0",
+ "ATTR_VALUE", attrValue, "LOWER_BOUND", lowerBound,
+ "SCALAR_INCREMENT", scalarIncrement);
throw InvalidArgument();
}
}