use phosphor-logging

Migrate all instances of std::cerr and std::cout to phosphor-logging
such as lg2::error, lg2::info, lg2::debug, ...

The use of modern logging infrastructure helps with development since
additional logging levels such as `debug` and `warning` are available.

Migrating the remaining logging calls helps to make the code more
readable and uniform.

Tested: Inspection, and on Tyan S8030

Restarted EM with patch applied.
Logs appear as usual.

```
Sep 15 13:52:46 s8030-bmc-30303035c0c1 entity-manager[23480]: Inventory Added: Supermicro PWS 920P SQ 0
Sep 15 13:52:46 s8030-bmc-30303035c0c1 entity-manager[23480]: Inventory Added: Supermicro PWS 920P SQ 1
Sep 15 13:52:46 s8030-bmc-30303035c0c1 entity-manager[23480]: Inventory Added: Tyan S8030 Baseboard
Sep 15 13:52:46 s8030-bmc-30303035c0c1 entity-manager[23480]: Inventory Added: MBX 1.57 Chassis
```

`busctl tree` output appears as before.

Did a power cycle to trigger a few more log prints

```
Sep 15 13:55:14 s8030-bmc-30303035c0c1 entity-manager[23480]: power match triggered
```

Created configuration file with missing fields to trigger error print.
```
{
  "Exposes": [],
  "Type": "error"
}
```

```
Sep 15 13:56:58 s8030-bmc-30303035c0c1 entity-manager[23659]: Finished loading json configuration in 7938ms
Sep 15 13:56:58 s8030-bmc-30303035c0c1 entity-manager[23659]: configuration file missing probe:
                                                               {"Exposes":[],"Type":"error"}
Sep 15 13:56:59 s8030-bmc-30303035c0c1 entity-manager[23659]: configuration file missing probe:
                                                               {"Exposes":[],"Type":"error"}
```

Change-Id: I3452f983c9c14cd02ab9b56451c4b3e4a13c3979
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/fru_device/fru_device.cpp b/src/fru_device/fru_device.cpp
index 2678f90..1b2de93 100644
--- a/src/fru_device/fru_device.cpp
+++ b/src/fru_device/fru_device.cpp
@@ -26,7 +26,6 @@
 #include <functional>
 #include <future>
 #include <iomanip>
-#include <iostream>
 #include <limits>
 #include <map>
 #include <optional>
@@ -112,7 +111,7 @@
     auto result = lseek(fd, offset, SEEK_SET);
     if (result < 0)
     {
-        std::cerr << "failed to seek\n";
+        lg2::error("failed to seek");
         return -1;
     }
 
@@ -351,7 +350,7 @@
     int file = open(path.c_str(), O_RDONLY);
     if (file < 0)
     {
-        std::cerr << "Unable to open eeprom file: " << path << "\n";
+        lg2::error("Unable to open eeprom file: {PATH}", "PATH", path);
         return {};
     }
 
@@ -383,7 +382,7 @@
     {
         if (ec)
         {
-            std::cerr << "directory_iterator err " << ec.message() << "\n";
+            lg2::error("directory_iterator err {ERR}", "ERR", ec.message());
             break;
         }
         const std::string node = p.path().string();
@@ -397,7 +396,7 @@
         }
         if (m.size() != 2)
         {
-            std::cerr << "regex didn't capture\n";
+            lg2::error("regex didn't capture");
             continue;
         }
 
@@ -510,8 +509,8 @@
             // Set target address
             if (ioctl(file, I2C_SLAVE, ii) < 0)
             {
-                std::cerr << "device at bus " << bus << " address " << ii
-                          << " busy\n";
+                lg2::error("device at bus {BUS} address {ADDR} busy", "BUS",
+                           bus, "ADDR", ii);
                 continue;
             }
             // probe
@@ -543,8 +542,8 @@
             std::optional<bool> is16Bit = isDevice16Bit(file, ii);
             if (!is16Bit.has_value())
             {
-                std::cerr << "failed to read bus " << bus << " address " << ii
-                          << "\n";
+                lg2::error("failed to read bus {BUS} address {ADDR}", "BUS",
+                           bus, "ADDR", ii);
                 if (powerIsOn)
                 {
                     failedItems.insert(ii);
@@ -594,7 +593,7 @@
         future.wait_for(std::chrono::seconds(busTimeoutSeconds));
     if (status == std::future_status::timeout)
     {
-        std::cerr << "Error reading bus " << bus << "\n";
+        lg2::error("Error reading bus {BUS}", "BUS", bus);
         if (powerIsOn)
         {
             busBlocklist[bus] = std::nullopt;
@@ -613,7 +612,7 @@
     if (!blocklistStream.good())
     {
         // File is optional.
-        std::cerr << "Cannot open blocklist file.\n\n";
+        lg2::error("Cannot open blocklist file.\n");
         return;
     }
 
@@ -621,8 +620,8 @@
         nlohmann::json::parse(blocklistStream, nullptr, false);
     if (data.is_discarded())
     {
-        std::cerr << "Illegal blocklist file detected, cannot validate JSON, "
-                     "exiting\n";
+        lg2::error(
+            "Illegal blocklist file detected, cannot validate JSON, exiting");
         std::exit(EXIT_FAILURE);
     }
 
@@ -631,7 +630,7 @@
     // such as specific addresses or ranges.
     if (data.type() != nlohmann::json::value_t::object)
     {
-        std::cerr << "Illegal blocklist, expected to read dictionary\n";
+        lg2::error("Illegal blocklist, expected to read dictionary");
         std::exit(EXIT_FAILURE);
     }
 
@@ -643,7 +642,7 @@
         if (buses.type() != nlohmann::json::value_t::array)
         {
             // Buses field present but invalid, therefore this is an error.
-            std::cerr << "Invalid contents for blocklist buses field\n";
+            lg2::error("Invalid contents for blocklist buses field");
             std::exit(EXIT_FAILURE);
         }
 
@@ -682,7 +681,7 @@
         catch (const nlohmann::detail::type_error& e)
         {
             // Type mis-match is a critical error.
-            std::cerr << "Invalid bus type: " << e.what() << "\n";
+            lg2::error("Invalid bus type: {ERR}", "ERR", e.what());
             std::exit(EXIT_FAILURE);
         }
     }
@@ -698,7 +697,7 @@
 
         if (bus < 0)
         {
-            std::cerr << "Cannot translate " << i2cBus << " to int\n";
+            lg2::error("Cannot translate {BUS} to int", "BUS", i2cBus);
             continue;
         }
         auto busFind = busBlocklist.find(bus);
@@ -722,25 +721,25 @@
         auto file = open(i2cBus.c_str(), O_RDWR);
         if (file < 0)
         {
-            std::cerr << "unable to open i2c device " << i2cBus.string()
-                      << "\n";
+            lg2::error("unable to open i2c device {PATH}", "PATH",
+                       i2cBus.string());
             continue;
         }
         unsigned long funcs = 0;
 
         if (ioctl(file, I2C_FUNCS, &funcs) < 0)
         {
-            std::cerr
-                << "Error: Could not get the adapter functionality matrix bus "
-                << bus << "\n";
+            lg2::error(
+                "Error: Could not get the adapter functionality matrix bus {BUS}",
+                "BUS", bus);
             close(file);
             continue;
         }
         if (((funcs & I2C_FUNC_SMBUS_READ_BYTE) == 0U) ||
             ((I2C_FUNC_SMBUS_READ_I2C_BLOCK) == 0))
         {
-            std::cerr << "Error: Can't use SMBus Receive Byte command bus "
-                      << bus << "\n";
+            lg2::error("Error: Can't use SMBus Receive Byte command bus {BUS}",
+                       "BUS", bus);
             close(file);
             continue;
         }
@@ -800,7 +799,7 @@
         device, formattedFRU, bus, address, unknownBusObjectCount);
     if (!optionalProductName)
     {
-        std::cerr << "getProductName failed. product name is empty.\n";
+        lg2::error("getProductName failed. product name is empty.");
         return;
     }
 
@@ -881,7 +880,7 @@
         }
         else if (!iface->register_property(key, property.second + '\0'))
         {
-            std::cerr << "illegal key: " << key << "\n";
+            lg2::error("illegal key: {KEY}", "KEY", key);
         }
         lg2::debug("parsed FRU property: {FIRST}: {SECOND}", "FIRST",
                    property.first, "SECOND", property.second);
@@ -920,13 +919,13 @@
     boost::container::flat_map<std::string, std::string> tmp;
     if (fru.size() > maxFruSize)
     {
-        std::cerr << "Invalid fru.size() during writeFRU\n";
+        lg2::error("Invalid fru.size() during writeFRU");
         return false;
     }
     // verify legal fru by running it through fru parsing logic
     if (formatIPMIFRU(fru, tmp) != resCodes::resOK)
     {
-        std::cerr << "Invalid fru format during writeFRU\n";
+        lg2::error("Invalid fru format during writeFRU");
         return false;
     }
     // baseboard fru
@@ -935,7 +934,8 @@
         std::ofstream file(baseboardFruLocation, std::ios_base::binary);
         if (!file.good())
         {
-            std::cerr << "Error opening file " << baseboardFruLocation << "\n";
+            lg2::error("Error opening file {PATH}", "PATH",
+                       baseboardFruLocation);
             throw DBusInternalError();
             return false;
         }
@@ -953,7 +953,7 @@
         int eeprom = open(path.c_str(), O_RDWR | O_CLOEXEC);
         if (eeprom < 0)
         {
-            std::cerr << "unable to open i2c device " << path << "\n";
+            lg2::error("unable to open i2c device {PATH}", "PATH", path);
             throw DBusInternalError();
             return false;
         }
@@ -973,8 +973,8 @@
 
         if (lseek(eeprom, offset, SEEK_SET) < 0)
         {
-            std::cerr << "Unable to seek to offset " << offset
-                      << " in device: " << path << "\n";
+            lg2::error("Unable to seek to offset {OFFSET} in device: {PATH}",
+                       "OFFSET", offset, "PATH", path);
             close(eeprom);
             throw DBusInternalError();
         }
@@ -982,7 +982,7 @@
         ssize_t writtenBytes = write(eeprom, fru.data(), fru.size());
         if (writtenBytes < 0)
         {
-            std::cerr << "unable to write to i2c device " << path << "\n";
+            lg2::error("unable to write to i2c device {PATH}", "PATH", path);
             close(eeprom);
             throw DBusInternalError();
             return false;
@@ -997,13 +997,13 @@
     int file = open(i2cBus.c_str(), O_RDWR | O_CLOEXEC);
     if (file < 0)
     {
-        std::cerr << "unable to open i2c device " << i2cBus << "\n";
+        lg2::error("unable to open i2c device {PATH}", "PATH", i2cBus);
         throw DBusInternalError();
         return false;
     }
     if (ioctl(file, I2C_SLAVE_FORCE, address) < 0)
     {
-        std::cerr << "unable to set device address\n";
+        lg2::error("unable to set device address");
         close(file);
         throw DBusInternalError();
         return false;
@@ -1021,7 +1021,7 @@
             // with the third bit being a memory page address bit.
             if (ioctl(file, I2C_SLAVE_FORCE, ++address) < 0)
             {
-                std::cerr << "unable to set device address\n";
+                lg2::error("unable to set device address");
                 close(file);
                 throw DBusInternalError();
                 return false;
@@ -1033,7 +1033,7 @@
         {
             if ((retries--) == 0U)
             {
-                std::cerr << "error writing fru: " << strerror(errno) << "\n";
+                lg2::error("error writing fru: {ERR}", "ERR", strerror(errno));
                 close(file);
                 throw DBusInternalError();
                 return false;
@@ -1077,8 +1077,8 @@
     {
         if (dbusCall)
         {
-            std::cerr << "Unable to access i2c bus " << static_cast<int>(busNum)
-                      << "\n";
+            lg2::error("Unable to access i2c bus {BUS}", "BUS",
+                       static_cast<int>(busNum));
             throw std::invalid_argument("Invalid Bus.");
         }
         return;
@@ -1139,7 +1139,7 @@
 
         if (ec)
         {
-            std::cerr << "Error in timer: " << ec.message() << "\n";
+            lg2::error("Error in timer: {ERR}", "ERR", ec.message());
             return;
         }
 
@@ -1149,7 +1149,7 @@
         boost::container::flat_map<size_t, fs::path> busPaths;
         if (!getI2cDevicePaths(devDir, busPaths))
         {
-            std::cerr << "unable to find i2c devices\n";
+            lg2::error("unable to find i2c devices");
             return;
         }
 
@@ -1321,7 +1321,7 @@
 
     if (!findFiles(devDir, matchString, i2cBuses))
     {
-        std::cerr << "unable to find i2c devices\n";
+        lg2::error("unable to find i2c devices");
         return 1;
     }
 
@@ -1408,7 +1408,7 @@
                              std::size_t bytesTransferred) {
             if (ec)
             {
-                std::cout << "Callback Error " << ec << "\n";
+                lg2::info("Callback Error {ERR}", "ERR", ec.message());
                 return;
             }
             size_t index = 0;
@@ -1429,8 +1429,8 @@
                             int bus = busStrToInt(name);
                             if (bus < 0)
                             {
-                                std::cerr
-                                    << "Could not parse bus " << name << "\n";
+                                lg2::error("Could not parse bus {BUS}", "BUS",
+                                           name);
                                 continue;
                             }
                             int rootBus = getRootBus(bus);