meson: use phosphor-logging for debug statements
There is no need to individually patch each file to enable debug
logging.
All the different definitions of 'bool debug' are removed in favor of
using phosphor-logging.
Change-Id: Ia9a8ecfa4ea220f588d7cf2d291b14067e0391e7
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/meson.build b/meson.build
index 93fd6a1..57ba3e1 100644
--- a/meson.build
+++ b/meson.build
@@ -35,13 +35,9 @@
endif
nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
+sdbusplus = dependency('sdbusplus', include_type: 'system')
+phosphor_logging_dep = dependency('phosphor-logging')
-sdbusplus = dependency('sdbusplus', required: false)
-if not sdbusplus.found()
- sdbusplus_proj = subproject('sdbusplus', required: true)
- sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
- sdbusplus = sdbusplus.as_system('system')
-endif
systemd = dependency('systemd')
systemd_system_unit_dir = systemd.get_variable(
'systemdsystemunitdir',
@@ -302,6 +298,7 @@
boost,
gtest,
nlohmann_json_dep,
+ phosphor_logging_dep,
sdbusplus,
valijson,
],
@@ -320,6 +317,7 @@
dependencies: [
boost,
gtest,
+ phosphor_logging_dep,
sdbusplus,
],
include_directories: 'src',
@@ -337,6 +335,7 @@
gtest,
gmock,
nlohmann_json_dep,
+ phosphor_logging_dep,
],
include_directories: 'src',
)
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index b265bf6..f2452f5 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -27,6 +27,7 @@
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
@@ -60,7 +61,6 @@
}
namespace fs = std::filesystem;
-static constexpr bool debug = false;
constexpr size_t maxFruSize = 512;
constexpr size_t maxEepromPageIndex = 255;
constexpr size_t busTimeoutSeconds = 10;
@@ -477,11 +477,8 @@
continue;
}
- if (debug)
- {
- std::cout << "something at bus " << bus << " addr " << ii
- << "\n";
- }
+ lg2::debug("something at bus {BUS}, addr {ADDR}", "BUS", bus,
+ "ADDR", ii);
makeProbeInterface(bus, ii, objServer);
@@ -708,18 +705,12 @@
// i2cdetect by default uses the range 0x03 to 0x77, as
// this is what we have tested with, use this range. Could be
// changed in future.
- if (debug)
- {
- std::cerr << "Scanning bus " << bus << "\n";
- }
+ lg2::debug("Scanning bus {BUS}", "BUS", bus);
// fd is closed in this function in case the bus locks up
getBusFRUs(file, 0x03, 0x77, bus, device, powerIsOn, objServer);
- if (debug)
- {
- std::cerr << "Done scanning bus " << bus << "\n";
- }
+ lg2::debug("Done scanning bus {BUS}", "BUS", bus);
}
}
@@ -825,10 +816,8 @@
{
std::cerr << "illegal key: " << key << "\n";
}
- if (debug)
- {
- std::cout << property.first << ": " << property.second << "\n";
- }
+ lg2::debug("parsed FRU property: {FIRST}: {SECOND}", "FIRST",
+ property.first, "SECOND", property.second);
}
// baseboard will be 0, 0
diff --git a/src/fru_utils.cpp b/src/fru_utils.cpp
index 15d4234..f39bbac 100644
--- a/src/fru_utils.cpp
+++ b/src/fru_utils.cpp
@@ -17,6 +17,8 @@
#include "fru_utils.hpp"
+#include <phosphor-logging/lg2.hpp>
+
#include <array>
#include <cstddef>
#include <cstdint>
@@ -35,7 +37,6 @@
#include <linux/i2c.h>
}
-static constexpr bool debug = false;
constexpr size_t fruVersion = 1; // Current FRU spec version number is 1
std::tm intelEpoch()
@@ -646,23 +647,18 @@
// ipmi spec format version number is currently at 1, verify it
if (blockData[0] != fruVersion)
{
- if (debug)
- {
- std::cerr << "FRU spec version " << (int)(blockData[0])
- << " not supported. Supported version is "
- << (int)(fruVersion) << "\n";
- }
+ lg2::debug(
+ "FRU spec version {VERSION} not supported. Supported version is {SUPPORTED_VERSION}",
+ "VERSION", lg2::hex, blockData[0], "SUPPORTED_VERSION", lg2::hex,
+ fruVersion);
return false;
}
// verify pad is set to 0
if (blockData[6] != 0x0)
{
- if (debug)
- {
- std::cerr << "PAD value in header is non zero, value is "
- << (int)(blockData[6]) << "\n";
- }
+ lg2::debug("Pad value in header is non zero, value is {VALUE}", "VALUE",
+ lg2::hex, blockData[6]);
return false;
}
@@ -691,12 +687,10 @@
if (sum != blockData[7])
{
- if (debug)
- {
- std::cerr << "Checksum " << (int)(blockData[7])
- << " is invalid. calculated checksum is " << (int)(sum)
- << "\n";
- }
+ lg2::debug(
+ "Checksum {CHECKSUM} is invalid. calculated checksum is {CALCULATED_CHECKSUM}",
+ "CHECKSUM", lg2::hex, blockData[7], "CALCULATED_CHECKSUM", lg2::hex,
+ sum);
return false;
}
return true;
@@ -737,11 +731,8 @@
return findFRUHeader(reader, errorHelp, blockData, baseOffset);
}
- if (debug)
- {
- std::cerr << "Illegal header " << errorHelp << " base offset "
- << baseOffset << "\n";
- }
+ lg2::debug("Illegal header {HEADER} base offset {OFFSET}", "HEADER",
+ errorHelp, "OFFSET", baseOffset);
return false;
}
diff --git a/src/meson.build b/src/meson.build
index 248404c..6565efc 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -15,6 +15,7 @@
dependencies: [
boost,
nlohmann_json_dep,
+ phosphor_logging_dep,
sdbusplus,
valijson,
],
@@ -39,6 +40,7 @@
boost,
i2c,
nlohmann_json_dep,
+ phosphor_logging_dep,
sdbusplus,
threads,
valijson,
diff --git a/src/overlay.cpp b/src/overlay.cpp
index f6d2476..ddbddb4 100644
--- a/src/overlay.cpp
+++ b/src/overlay.cpp
@@ -27,6 +27,7 @@
#include <boost/container/flat_set.hpp>
#include <boost/process/child.hpp>
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <filesystem>
#include <iomanip>
@@ -39,8 +40,6 @@
constexpr const char* i2CDevsDir = "/sys/bus/i2c/devices";
constexpr const char* muxSymlinkDir = "/dev/i2c-mux";
-constexpr const bool debug = false;
-
const std::regex illegalNameRegex("[^A-Za-z0-9_]");
// helper function to make json types into string
@@ -315,11 +314,8 @@
// this error message is not printed in all situations.
// If wondering why your device not appearing, add your type to
// the exportTemplates array in the devices.hpp file.
- if constexpr (debug)
- {
- std::cerr << "Device type " << type
- << " not found in export map allowlist\n";
- }
+ lg2::debug("Device type {TYPE} not found in export map allowlist",
+ "TYPE", type);
}
}
diff --git a/src/perform_probe.cpp b/src/perform_probe.cpp
index c49ff7a..c88ed5a 100644
--- a/src/perform_probe.cpp
+++ b/src/perform_probe.cpp
@@ -17,12 +17,11 @@
#include "entity_manager.hpp"
#include <boost/algorithm/string/replace.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <regex>
#include <utility>
-constexpr const bool debug = false;
-
// probes dbus interface dictionary for a key with a value that matches a regex
// When an interface passes a probe, also save its D-Bus path with it.
bool probeDbus(const std::string& interfaceName,
@@ -63,11 +62,8 @@
}
if (deviceMatches)
{
- if constexpr (debug)
- {
- std::cerr << "probeDBus: Found probe match on " << path << " "
- << interfaceName << "\n";
- }
+ lg2::debug("Found probe match on {PATH} {IFACE}", "PATH", path,
+ "IFACE", interfaceName);
devices.emplace_back(interface, path);
foundMatch = true;
}
diff --git a/src/perform_scan.cpp b/src/perform_scan.cpp
index e787360..91372e4 100644
--- a/src/perform_scan.cpp
+++ b/src/perform_scan.cpp
@@ -20,6 +20,7 @@
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <charconv>
@@ -38,8 +39,6 @@
constexpr const int32_t maxMapperDepth = 0;
-constexpr const bool debug = false;
-
struct DBusInterfaceInstance
{
std::string busName;
@@ -82,11 +81,6 @@
},
instance.busName, instance.path, "org.freedesktop.DBus.Properties",
"GetAll", instance.interface);
-
- if constexpr (debug)
- {
- std::cerr << __LINE__ << "\n";
- }
}
static void registerCallback(nlohmann::json& systemConfiguration,
@@ -201,11 +195,6 @@
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", maxMapperDepth,
interfaces);
-
- if constexpr (debug)
- {
- std::cerr << __LINE__ << "\n";
- }
}
static std::string getRecordName(const DBusInterface& probe,
@@ -227,10 +216,7 @@
// hashes are hard to distinguish, use the non-hashed version if we want
// debug
- if constexpr (debug)
- {
- return probeName + device.dump();
- }
+ // return probeName + device.dump();
return std::to_string(std::hash<std::string>{}(probeName + device.dump()));
}
@@ -655,10 +641,6 @@
// about a dbus interface
findDbusObjects(std::move(dbusProbePointers),
std::move(dbusProbeInterfaces), shared_from_this());
- if constexpr (debug)
- {
- std::cerr << __LINE__ << "\n";
- }
}
PerformScan::~PerformScan()
@@ -671,19 +653,9 @@
nextScan->passedProbes = std::move(passedProbes);
nextScan->dbusProbeObjects = std::move(dbusProbeObjects);
nextScan->run();
-
- if constexpr (debug)
- {
- std::cerr << __LINE__ << "\n";
- }
}
else
{
_callback();
-
- if constexpr (debug)
- {
- std::cerr << __LINE__ << "\n";
- }
}
}
diff --git a/subprojects/phosphor-logging.wrap b/subprojects/phosphor-logging.wrap
new file mode 100644
index 0000000..71eee8b
--- /dev/null
+++ b/subprojects/phosphor-logging.wrap
@@ -0,0 +1,6 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-logging.git
+revision = HEAD
+
+[provide]
+phosphor-logging = phosphor_logging_dep
diff --git a/subprojects/sdbusplus.wrap b/subprojects/sdbusplus.wrap
index d470130..7b076d0 100644
--- a/subprojects/sdbusplus.wrap
+++ b/subprojects/sdbusplus.wrap
@@ -1,3 +1,6 @@
[wrap-git]
url = https://github.com/openbmc/sdbusplus.git
revision = HEAD
+
+[provide]
+sdbusplus = sdbusplus_dep