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/entity_manager/perform_scan.cpp b/src/entity_manager/perform_scan.cpp
index c71fa48..4a3696f 100644
--- a/src/entity_manager/perform_scan.cpp
+++ b/src/entity_manager/perform_scan.cpp
@@ -12,7 +12,6 @@
#include <phosphor-logging/lg2.hpp>
#include <charconv>
-#include <iostream>
using GetSubTreeType = std::vector<
std::pair<std::string,
@@ -35,8 +34,9 @@
{
if (retries == 0U)
{
- std::cerr << "retries exhausted on " << instance.busName << " "
- << instance.path << " " << instance.interface << "\n";
+ lg2::error("retries exhausted on {BUSNAME} {PATH} {INTF}", "BUSNAME",
+ instance.busName, "PATH", instance.path, "INTF",
+ instance.interface);
return;
}
@@ -45,9 +45,9 @@
&io](boost::system::error_code& errc, const DBusInterface& resp) {
if (errc)
{
- std::cerr << "error calling getall on " << instance.busName
- << " " << instance.path << " "
- << instance.interface << "\n";
+ lg2::error("error calling getall on {BUSNAME} {PATH} {INTF}",
+ "BUSNAME", instance.busName, "PATH", instance.path,
+ "INTF", instance.interface);
auto timer = std::make_shared<boost::asio::steady_timer>(io);
timer->expires_after(std::chrono::seconds(2));
@@ -125,7 +125,7 @@
{
return; // wasn't found by mapper
}
- std::cerr << "Error communicating to mapper.\n";
+ lg2::error("Error communicating to mapper.");
if (retries == 0U)
{
@@ -220,7 +220,7 @@
auto nameIt = record.find("Name");
if (nameIt == record.end())
{
- std::cerr << "Last JSON Illegal\n";
+ lg2::error("Last JSON Illegal");
return;
}
@@ -258,7 +258,7 @@
{
if (!value.is_string())
{
- std::cerr << "Value is invalid type " << value << "\n";
+ lg2::error("Value is invalid type {VALUE}", "VALUE", value);
break;
}
matches.emplace_back(value);
@@ -267,7 +267,7 @@
return true;
}
- std::cerr << "Value is invalid type " << keyPair.key() << "\n";
+ lg2::error("Value is invalid type {KEY}", "KEY", keyPair.key());
return false;
}
@@ -369,8 +369,9 @@
if (!matches.empty())
{
- std::cerr << "configuration file dependency error, could not find "
- << keyPair.key() << " " << keyPair.value() << "\n";
+ lg2::error(
+ "configuration file dependency error, could not find {KEY} {VALUE}",
+ "KEY", keyPair.key(), "VALUE", keyPair.value());
}
}
@@ -398,9 +399,9 @@
if (replaceStr)
{
- std::cerr << "Duplicates found, replacing " << *replaceStr
- << " with found device index.\n Consider "
- "fixing template to not have duplicates\n";
+ lg2::error(
+ "Duplicates found, replacing {STR} with found device index. Consider fixing template to not have duplicates",
+ "STR", *replaceStr);
}
return copyIt.value();
@@ -473,7 +474,7 @@
auto getName = record.find("Name");
if (getName == record.end())
{
- std::cerr << "Record Missing Name! " << record.dump();
+ lg2::error("Record Missing Name! {JSON}", "JSON", record.dump());
continue; // this should be impossible at this level
}
@@ -532,7 +533,8 @@
auto findProbe = it->find("Probe");
if (findProbe == it->end())
{
- std::cerr << "configuration file missing probe:\n " << *it << "\n";
+ lg2::error("configuration file missing probe:\n {JSON}", "JSON",
+ *it);
it = _configurations.erase(it);
continue;
}
@@ -540,7 +542,8 @@
auto findName = it->find("Name");
if (findName == it->end())
{
- std::cerr << "configuration file missing name:\n " << *it << "\n";
+ lg2::error("configuration file missing name:\n {JSON}", "JSON",
+ *it);
it = _configurations.erase(it);
continue;
}
@@ -578,7 +581,7 @@
const std::string* probe = probeJson.get_ptr<const std::string*>();
if (probe == nullptr)
{
- std::cerr << "Probe statement wasn't a string, can't parse";
+ lg2::error("Probe statement wasn't a string, can't parse");
continue;
}
if (probe::findProbeType(*probe))