logging: switch networkd static_library to lg2
This commit switches logging to lg2 in the following files -
1. src/dhcp_configuration.cpp
2. src/dhcp_configuration.cpp
3. src/ipaddress.cpp
4. src/system_configuration.cpp
5. src/system_queries.cpp
Tested: Build passes with "ninja -C build".
Change-Id: I492c7579c968810b783836b652e450ff89b8cd4b
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index 5907f4a..3465721 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -8,7 +8,7 @@
#include <filesystem>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace phosphor
@@ -19,7 +19,6 @@
{
using namespace phosphor::network;
-using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Configuration::Configuration(sdbusplus::bus_t& bus,
@@ -44,9 +43,8 @@
}
if (newest_file != std::filesystem::directory_entry{})
{
- log<level::INFO>(fmt::format("Using DHCP options from {}",
- newest_file.path().native())
- .c_str());
+ lg2::info("Using DHCP options from {FILE}", "FILE",
+ newest_file.path().native());
conf.setFile(newest_file.path());
}
diff --git a/src/dns_updater.cpp b/src/dns_updater.cpp
index 22693f8..5d9e417 100644
--- a/src/dns_updater.cpp
+++ b/src/dns_updater.cpp
@@ -2,7 +2,7 @@
#include <fstream>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -23,16 +23,14 @@
std::fstream outStream(outFile, std::fstream::out);
if (!outStream.is_open())
{
- log<level::ERR>("Unable to open output file",
- entry("FILE=%s", outFile.c_str()));
+ lg2::error("Unable to open output file {FILE}", "FILE", outFile);
elog<InternalFailure>();
}
std::fstream inStream(inFile, std::fstream::in);
if (!inStream.is_open())
{
- log<level::ERR>("Unable to open the input file",
- entry("FILE=%s", inFile.c_str()));
+ lg2::error("Unable to open the input file {FILE}", "FILE", inFile);
elog<InternalFailure>();
}
diff --git a/src/ipaddress.cpp b/src/ipaddress.cpp
index 62ac220..2235550 100644
--- a/src/ipaddress.cpp
+++ b/src/ipaddress.cpp
@@ -5,7 +5,7 @@
#include "util.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <stdexcept>
#include <string>
#include <string_view>
@@ -91,10 +91,10 @@
{
if (origin() != IP::AddressOrigin::Static)
{
- log<level::ERR>("Tried to delete a non-static address"),
- entry("ADDRESS=%s", address().c_str()),
- entry("PREFIX=%" PRIu8, prefixLength()),
- entry("INTERFACE=%s", parent.get().interfaceName().c_str());
+ lg2::error("Tried to delete a non-static address {IP_ADDRESS} prefix "
+ "{PREFIX} interface {INTERFACE_NAME}",
+ "IP_ADDRESS", address(), "PREFIX", prefixLength(),
+ "INTERFACE_NAME", parent.get().interfaceName());
elog<InternalFailure>();
}
diff --git a/src/system_configuration.cpp b/src/system_configuration.cpp
index 58b6dfc..f817dfe 100644
--- a/src/system_configuration.cpp
+++ b/src/system_configuration.cpp
@@ -1,7 +1,7 @@
#include "system_configuration.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <stdplus/pinned.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -14,7 +14,6 @@
static constexpr char HOSTNAMED_OBJ[] = "/org/freedesktop/hostname1";
static constexpr char HOSTNAMED_INTF[] = "org.freedesktop.hostname1";
-using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
static constexpr char propMatch[] =
@@ -44,10 +43,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- fmt::format("Hostname match parsing failed: {}", e.what())
- .c_str(),
- entry("ERROR=%s", e.what()));
+ lg2::error("Hostname match parsing failed: {ERROR}", "ERROR",
+ e);
}
})
{
@@ -65,8 +62,7 @@
}
catch (const std::exception& e)
{
- auto msg = fmt::format("Failed to get hostname: {}", e.what());
- log<level::ERR>(msg.c_str(), entry("ERROR=%s", e.what()));
+ lg2::error("Failed to get hostname: {ERROR}", "ERROR", e);
}
emit_object_added();
@@ -88,8 +84,7 @@
}
catch (const std::exception& e)
{
- auto msg = fmt::format("Failed to set hostname: {}", e.what());
- log<level::ERR>(msg.c_str(), entry("ERROR=%s", e.what()));
+ lg2::error("Failed to set hostname: {ERROR}", "ERROR", e);
}
return SystemConfigIntf::hostName();
}
diff --git a/src/system_queries.cpp b/src/system_queries.cpp
index 9a8cba8..6c59547 100644
--- a/src/system_queries.cpp
+++ b/src/system_queries.cpp
@@ -10,7 +10,7 @@
#include <algorithm>
#include <optional>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <stdexcept>
#include <stdplus/fd/create.hpp>
#include <stdplus/util/cexec.hpp>
@@ -20,9 +20,6 @@
{
using std::literals::string_view_literals::operator""sv;
-using phosphor::logging::entry;
-using phosphor::logging::level;
-using phosphor::logging::log;
static stdplus::Fd& getIFSock()
{
@@ -69,10 +66,8 @@
if (unsupported.find(ukey) == unsupported.end())
{
unsupported.emplace(std::move(ukey));
- auto msg =
- fmt::format("{} not supported on {}", cmdname, ifname);
- log<level::INFO>(msg.c_str(),
- entry("INTERFACE=%s", ifname.c_str()));
+ lg2::info("{CMD_NAME} not supported on {INTERFACE_NAME}",
+ "CMD_NAME", cmdname, "INTERFACE_NAME", ifname);
}
return ret;
}