logging: switch networkd static_library to lg2

This commit switches logging to lg2 in the following files -
1. src/network_manager.cpp
2. src/util.cpp
3. src/ethernet_interface.cpp

Tested: Build passes with "ninja -C build".
Change-Id: Ib2492116ecf3f41f9cd0146dc4b5389a59bce87c
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 5e61cbd..c5d6bdc 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -15,7 +15,7 @@
 #include <algorithm>
 #include <filesystem>
 #include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <stdplus/raw.hpp>
 #include <stdplus/zstring.hpp>
 #include <string>
@@ -56,8 +56,8 @@
     }
     catch (const std::exception& e)
     {
-        auto err = fmt::format("{} failed on {}: {}", msg, intf, e.what());
-        log<level::ERR>(err.c_str(), entry("INTERFACE=%s", intf.c_str()));
+        lg2::error("{MSG} failed on {INTERFACE_NAME}: {ERROR}", "MSG", msg,
+                   "INTERFACE_NAME", intf, "ERROR", e);
     }
     return fallback;
 }
@@ -195,8 +195,8 @@
 {
     if (!info.mac || !info.addr)
     {
-        auto msg = fmt::format("Missing neighbor mac on {}\n", interfaceName());
-        log<level::ERR>(msg.c_str());
+        lg2::error("Missing neighbor mac on {INTERFACE_NAME}", "INTERFACE_NAME",
+                   interfaceName());
         return;
     }
 
@@ -233,8 +233,8 @@
     }
     catch (const std::exception& e)
     {
-        auto msg = fmt::format("Invalid IP `{}`: {}\n", ipaddress, e.what());
-        log<level::ERR>(msg.c_str(), entry("ADDRESS=%s", ipaddress.c_str()));
+        lg2::error("Invalid IP {IP_ADDRESS}: {ERROR}", "IP_ADDRESS", ipaddress,
+                   "ERROR", e);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("ipaddress"),
                               Argument::ARGUMENT_VALUE(ipaddress.c_str()));
     }
@@ -245,10 +245,8 @@
     }
     catch (const std::exception& e)
     {
-        auto msg = fmt::format("Invalid prefix length `{}`: {}\n", prefixLength,
-                               e.what());
-        log<level::ERR>(msg.c_str(),
-                        entry("PREFIXLENGTH=%" PRIu8, prefixLength));
+        lg2::error("Invalid prefix length {PREFIXLENGTH}: {ERROR}",
+                   "PREFIXLENGTH", prefixLength, "ERROR", e);
         elog<InvalidArgument>(
             Argument::ARGUMENT_NAME("prefixLength"),
             Argument::ARGUMENT_VALUE(std::to_string(prefixLength).c_str()));
@@ -287,9 +285,8 @@
     }
     catch (const std::exception& e)
     {
-        auto msg =
-            fmt::format("Not a valid IP address `{}`: {}", ipAddress, e.what());
-        log<level::ERR>(msg.c_str(), entry("ADDRESS=%s", ipAddress.c_str()));
+        lg2::error("Not a valid IP address {IP_ADDRESS}: {ERROR}", "IP_ADDRESS",
+                   ipAddress, "ERROR", e);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("ipAddress"),
                               Argument::ARGUMENT_VALUE(ipAddress.c_str()));
     }
@@ -301,10 +298,8 @@
     }
     catch (const std::exception& e)
     {
-        auto msg = fmt::format("Not a valid MAC address `{}`: {}", macAddress,
-                               e.what());
-        log<level::ERR>(msg.c_str(),
-                        entry("MACADDRESS=%s", macAddress.c_str()));
+        lg2::error("Not a valid MAC address {MAC_ADDRESS}: {ERROR}",
+                   "MAC_ADDRESS", macAddress, "ERROR", e);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("macAddress"),
                               Argument::ARGUMENT_VALUE(macAddress.c_str()));
     }
@@ -443,9 +438,8 @@
         }
         catch (const std::exception& e)
         {
-            auto msg =
-                fmt::format("Not a valid IP address `{}`: {}", ip, e.what());
-            log<level::ERR>(msg.c_str()), entry("ADDRESS=%s", ip.c_str());
+            lg2::error("Not a valid IP address {IP_ADDRESS}: {ERROR}",
+                       "IP_ADDRESS", ip, "ERROR", e);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("StaticNameserver"),
                                   Argument::ARGUMENT_VALUE(ip.c_str()));
         }
@@ -459,7 +453,7 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Exception processing DNS entries");
+        lg2::error("Exception processing DNS entries: {ERROR}", "ERROR", e);
     }
     return EthernetInterfaceIntf::staticNameServers();
 }
@@ -496,8 +490,9 @@
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
-        log<level::ERR>(
-            "Failed to get NTP server information from Systemd-Timesyncd");
+        lg2::error("Failed to get NTP server information from "
+                   "Systemd-Timesyncd: {ERROR}",
+                   "ERROR", e);
     }
 
     return servers;
@@ -538,7 +533,9 @@
     }
     catch (const sdbusplus::exception_t& e)
     {
-        log<level::ERR>("Failed to get DNS information from Systemd-Resolved");
+        lg2::error(
+            "Failed to get DNS information from Systemd-Resolved: {ERROR}",
+            "ERROR", e);
     }
     auto tupleVector = std::get_if<type>(&name);
     for (auto i = tupleVector->begin(); i != tupleVector->end(); ++i)
@@ -558,7 +555,7 @@
     if (manager.get().interfaces.find(intfName) !=
         manager.get().interfaces.end())
     {
-        log<level::ERR>("VLAN already exists", entry("VLANID=%u", id));
+        lg2::error("VLAN {VLAN_ID} already exists", "VLAN_ID", id);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("VLANId"),
                               Argument::ARGUMENT_VALUE(idStr.c_str()));
     }
@@ -614,7 +611,7 @@
     }
     catch (InternalFailure& e)
     {
-        log<level::ERR>("Exception processing NTP entries");
+        lg2::error("Exception processing NTP entries: {ERROR}", "ERROR", e);
     }
     return EthernetInterfaceIntf::staticNTPServers();
 }
@@ -740,15 +737,14 @@
     auto path =
         config::pathForIntfConf(manager.get().getConfDir(), interfaceName());
     config.writeFile(path);
-    auto msg = fmt::format("Wrote networkd file: {}", path.native());
-    log<level::INFO>(msg.c_str(), entry("FILE=%s", path.c_str()));
+    lg2::info("Wrote networkd file: {FILE_PATH}", "FILE_PATH", path);
 }
 
 std::string EthernetInterface::macAddress([[maybe_unused]] std::string value)
 {
     if (vlan)
     {
-        log<level::ERR>("Tried to set MAC address on VLAN");
+        lg2::error("Tried to set MAC address on VLAN");
         elog<InternalFailure>();
     }
 #ifdef PERSIST_MAC
@@ -759,15 +755,15 @@
     }
     catch (const std::invalid_argument&)
     {
-        log<level::ERR>("MACAddress is not valid.",
-                        entry("MAC=%s", value.c_str()));
+        lg2::error("MAC Address {MAC_ADDRESS} is not valid", "MAC_ADDRESS",
+                   value);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("MACAddress"),
                               Argument::ARGUMENT_VALUE(value.c_str()));
     }
     if (!mac_address::isUnicast(newMAC))
     {
-        log<level::ERR>("MACAddress is not valid.",
-                        entry("MAC=%s", value.c_str()));
+        lg2::error("MAC Address {MAC_ADDRESS} is not valid", "MAC_ADDRESS",
+                   value);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("MACAddress"),
                               Argument::ARGUMENT_VALUE(value.c_str()));
     }
@@ -836,8 +832,8 @@
     }
     catch (const std::exception& e)
     {
-        auto msg = fmt::format("Invalid v4 GW `{}`: {}", gateway, e.what());
-        log<level::ERR>(msg.c_str(), entry("GATEWAY=%s", gateway.c_str()));
+        lg2::error("Invalid v4 GW {GATEWAY}: {ERROR}", "GATEWAY", gateway,
+                   "ERROR", e);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("GATEWAY"),
                               Argument::ARGUMENT_VALUE(gateway.c_str()));
     }
@@ -865,8 +861,8 @@
     }
     catch (const std::exception& e)
     {
-        auto msg = fmt::format("Invalid v6 GW `{}`: {}", gateway, e.what());
-        log<level::ERR>(msg.c_str(), entry("GATEWAY=%s", gateway.c_str()));
+        lg2::error("Invalid v6 GW {GATEWAY}: {ERROR}", "GATEWAY", gateway,
+                   "ERROR", e);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("GATEWAY"),
                               Argument::ARGUMENT_VALUE(gateway.c_str()));
     }