Skip to content

Commit c3db2c3

Browse files
committed
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 <[email protected]>
1 parent e2c84df commit c3db2c3

File tree

9 files changed

+45
-91
lines changed

9 files changed

+45
-91
lines changed

meson.build

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ if get_option('fru-device')
3535
endif
3636

3737
nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
38+
sdbusplus = dependency('sdbusplus', include_type: 'system')
39+
phosphor_logging_dep = dependency('phosphor-logging')
3840

39-
sdbusplus = dependency('sdbusplus', required: false)
40-
if not sdbusplus.found()
41-
sdbusplus_proj = subproject('sdbusplus', required: true)
42-
sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
43-
sdbusplus = sdbusplus.as_system('system')
44-
endif
4541
systemd = dependency('systemd')
4642
systemd_system_unit_dir = systemd.get_variable(
4743
'systemdsystemunitdir',
@@ -302,6 +298,7 @@ if not build_tests.disabled()
302298
boost,
303299
gtest,
304300
nlohmann_json_dep,
301+
phosphor_logging_dep,
305302
sdbusplus,
306303
valijson,
307304
],
@@ -320,6 +317,7 @@ if not build_tests.disabled()
320317
dependencies: [
321318
boost,
322319
gtest,
320+
phosphor_logging_dep,
323321
sdbusplus,
324322
],
325323
include_directories: 'src',
@@ -337,6 +335,7 @@ if not build_tests.disabled()
337335
gtest,
338336
gmock,
339337
nlohmann_json_dep,
338+
phosphor_logging_dep,
340339
],
341340
include_directories: 'src',
342341
)

src/fru_device.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <boost/asio/steady_timer.hpp>
2828
#include <boost/container/flat_map.hpp>
2929
#include <nlohmann/json.hpp>
30+
#include <phosphor-logging/lg2.hpp>
3031
#include <sdbusplus/asio/connection.hpp>
3132
#include <sdbusplus/asio/object_server.hpp>
3233

@@ -60,7 +61,6 @@ extern "C"
6061
}
6162

6263
namespace fs = std::filesystem;
63-
static constexpr bool debug = false;
6464
constexpr size_t maxFruSize = 512;
6565
constexpr size_t maxEepromPageIndex = 255;
6666
constexpr size_t busTimeoutSeconds = 10;
@@ -477,11 +477,8 @@ int getBusFRUs(int file, int first, int last, int bus,
477477
continue;
478478
}
479479

480-
if (debug)
481-
{
482-
std::cout << "something at bus " << bus << " addr " << ii
483-
<< "\n";
484-
}
480+
lg2::debug("something at bus {BUS}, addr {ADDR}", "BUS", bus,
481+
"ADDR", ii);
485482

486483
makeProbeInterface(bus, ii, objServer);
487484

@@ -708,18 +705,12 @@ static void findI2CDevices(const std::vector<fs::path>& i2cBuses,
708705
// i2cdetect by default uses the range 0x03 to 0x77, as
709706
// this is what we have tested with, use this range. Could be
710707
// changed in future.
711-
if (debug)
712-
{
713-
std::cerr << "Scanning bus " << bus << "\n";
714-
}
708+
lg2::debug("Scanning bus {BUS}", "BUS", bus);
715709

716710
// fd is closed in this function in case the bus locks up
717711
getBusFRUs(file, 0x03, 0x77, bus, device, powerIsOn, objServer);
718712

719-
if (debug)
720-
{
721-
std::cerr << "Done scanning bus " << bus << "\n";
722-
}
713+
lg2::debug("Done scanning bus {BUS}", "BUS", bus);
723714
}
724715
}
725716

@@ -825,10 +816,8 @@ void addFruObjectToDbus(
825816
{
826817
std::cerr << "illegal key: " << key << "\n";
827818
}
828-
if (debug)
829-
{
830-
std::cout << property.first << ": " << property.second << "\n";
831-
}
819+
lg2::debug("parsed FRU property: {FIRST}: {SECOND}", "FIRST",
820+
property.first, "SECOND", property.second);
832821
}
833822

834823
// baseboard will be 0, 0

src/fru_utils.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "fru_utils.hpp"
1919

20+
#include <phosphor-logging/lg2.hpp>
21+
2022
#include <array>
2123
#include <cstddef>
2224
#include <cstdint>
@@ -35,7 +37,6 @@ extern "C"
3537
#include <linux/i2c.h>
3638
}
3739

38-
static constexpr bool debug = false;
3940
constexpr size_t fruVersion = 1; // Current FRU spec version number is 1
4041

4142
std::tm intelEpoch()
@@ -646,23 +647,18 @@ bool validateHeader(const std::array<uint8_t, I2C_SMBUS_BLOCK_MAX>& blockData)
646647
// ipmi spec format version number is currently at 1, verify it
647648
if (blockData[0] != fruVersion)
648649
{
649-
if (debug)
650-
{
651-
std::cerr << "FRU spec version " << (int)(blockData[0])
652-
<< " not supported. Supported version is "
653-
<< (int)(fruVersion) << "\n";
654-
}
650+
lg2::debug(
651+
"FRU spec version {VERSION} not supported. Supported version is {SUPPORTED_VERSION}",
652+
"VERSION", lg2::hex, blockData[0], "SUPPORTED_VERSION", lg2::hex,
653+
fruVersion);
655654
return false;
656655
}
657656

658657
// verify pad is set to 0
659658
if (blockData[6] != 0x0)
660659
{
661-
if (debug)
662-
{
663-
std::cerr << "PAD value in header is non zero, value is "
664-
<< (int)(blockData[6]) << "\n";
665-
}
660+
lg2::debug("Pad value in header is non zero, value is {VALUE}", "VALUE",
661+
lg2::hex, blockData[6]);
666662
return false;
667663
}
668664

@@ -691,12 +687,10 @@ bool validateHeader(const std::array<uint8_t, I2C_SMBUS_BLOCK_MAX>& blockData)
691687

692688
if (sum != blockData[7])
693689
{
694-
if (debug)
695-
{
696-
std::cerr << "Checksum " << (int)(blockData[7])
697-
<< " is invalid. calculated checksum is " << (int)(sum)
698-
<< "\n";
699-
}
690+
lg2::debug(
691+
"Checksum {CHECKSUM} is invalid. calculated checksum is {CALCULATED_CHECKSUM}",
692+
"CHECKSUM", lg2::hex, blockData[7], "CALCULATED_CHECKSUM", lg2::hex,
693+
sum);
700694
return false;
701695
}
702696
return true;
@@ -737,11 +731,8 @@ bool findFRUHeader(FRUReader& reader, const std::string& errorHelp,
737731
return findFRUHeader(reader, errorHelp, blockData, baseOffset);
738732
}
739733

740-
if (debug)
741-
{
742-
std::cerr << "Illegal header " << errorHelp << " base offset "
743-
<< baseOffset << "\n";
744-
}
734+
lg2::debug("Illegal header {HEADER} base offset {OFFSET}", "HEADER",
735+
errorHelp, "OFFSET", baseOffset);
745736

746737
return false;
747738
}

src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ executable(
1515
dependencies: [
1616
boost,
1717
nlohmann_json_dep,
18+
phosphor_logging_dep,
1819
sdbusplus,
1920
valijson,
2021
],
@@ -39,6 +40,7 @@ if get_option('fru-device')
3940
boost,
4041
i2c,
4142
nlohmann_json_dep,
43+
phosphor_logging_dep,
4244
sdbusplus,
4345
threads,
4446
valijson,

src/overlay.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <boost/container/flat_set.hpp>
2828
#include <boost/process/child.hpp>
2929
#include <nlohmann/json.hpp>
30+
#include <phosphor-logging/lg2.hpp>
3031

3132
#include <filesystem>
3233
#include <iomanip>
@@ -39,8 +40,6 @@ constexpr const char* templateChar = "$";
3940
constexpr const char* i2CDevsDir = "/sys/bus/i2c/devices";
4041
constexpr const char* muxSymlinkDir = "/dev/i2c-mux";
4142

42-
constexpr const bool debug = false;
43-
4443
const std::regex illegalNameRegex("[^A-Za-z0-9_]");
4544

4645
// helper function to make json types into string
@@ -315,11 +314,8 @@ bool loadOverlays(const nlohmann::json& systemConfiguration)
315314
// this error message is not printed in all situations.
316315
// If wondering why your device not appearing, add your type to
317316
// the exportTemplates array in the devices.hpp file.
318-
if constexpr (debug)
319-
{
320-
std::cerr << "Device type " << type
321-
<< " not found in export map allowlist\n";
322-
}
317+
lg2::debug("Device type {TYPE} not found in export map allowlist",
318+
"TYPE", type);
323319
}
324320
}
325321

src/perform_probe.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
#include "entity_manager.hpp"
1818

1919
#include <boost/algorithm/string/replace.hpp>
20+
#include <phosphor-logging/lg2.hpp>
2021

2122
#include <regex>
2223
#include <utility>
2324

24-
constexpr const bool debug = false;
25-
2625
// probes dbus interface dictionary for a key with a value that matches a regex
2726
// When an interface passes a probe, also save its D-Bus path with it.
2827
bool probeDbus(const std::string& interfaceName,
@@ -63,11 +62,8 @@ bool probeDbus(const std::string& interfaceName,
6362
}
6463
if (deviceMatches)
6564
{
66-
if constexpr (debug)
67-
{
68-
std::cerr << "probeDBus: Found probe match on " << path << " "
69-
<< interfaceName << "\n";
70-
}
65+
lg2::debug("Found probe match on {PATH} {IFACE}", "PATH", path,
66+
"IFACE", interfaceName);
7167
devices.emplace_back(interface, path);
7268
foundMatch = true;
7369
}

src/perform_scan.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <boost/asio/steady_timer.hpp>
2121
#include <boost/container/flat_map.hpp>
2222
#include <boost/container/flat_set.hpp>
23+
#include <phosphor-logging/lg2.hpp>
2324

2425
#include <charconv>
2526

@@ -38,8 +39,6 @@ using GetSubTreeType = std::vector<
3839

3940
constexpr const int32_t maxMapperDepth = 0;
4041

41-
constexpr const bool debug = false;
42-
4342
struct DBusInterfaceInstance
4443
{
4544
std::string busName;
@@ -82,11 +81,6 @@ void getInterfaces(
8281
},
8382
instance.busName, instance.path, "org.freedesktop.DBus.Properties",
8483
"GetAll", instance.interface);
85-
86-
if constexpr (debug)
87-
{
88-
std::cerr << __LINE__ << "\n";
89-
}
9084
}
9185

9286
static void registerCallback(nlohmann::json& systemConfiguration,
@@ -201,11 +195,6 @@ void findDbusObjects(std::vector<std::shared_ptr<PerformProbe>>&& probeVector,
201195
"/xyz/openbmc_project/object_mapper",
202196
"xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", maxMapperDepth,
203197
interfaces);
204-
205-
if constexpr (debug)
206-
{
207-
std::cerr << __LINE__ << "\n";
208-
}
209198
}
210199

211200
static std::string getRecordName(const DBusInterface& probe,
@@ -227,10 +216,7 @@ static std::string getRecordName(const DBusInterface& probe,
227216

228217
// hashes are hard to distinguish, use the non-hashed version if we want
229218
// debug
230-
if constexpr (debug)
231-
{
232-
return probeName + device.dump();
233-
}
219+
// return probeName + device.dump();
234220

235221
return std::to_string(std::hash<std::string>{}(probeName + device.dump()));
236222
}
@@ -655,10 +641,6 @@ void PerformScan::run()
655641
// about a dbus interface
656642
findDbusObjects(std::move(dbusProbePointers),
657643
std::move(dbusProbeInterfaces), shared_from_this());
658-
if constexpr (debug)
659-
{
660-
std::cerr << __LINE__ << "\n";
661-
}
662644
}
663645

664646
PerformScan::~PerformScan()
@@ -671,19 +653,9 @@ PerformScan::~PerformScan()
671653
nextScan->passedProbes = std::move(passedProbes);
672654
nextScan->dbusProbeObjects = std::move(dbusProbeObjects);
673655
nextScan->run();
674-
675-
if constexpr (debug)
676-
{
677-
std::cerr << __LINE__ << "\n";
678-
}
679656
}
680657
else
681658
{
682659
_callback();
683-
684-
if constexpr (debug)
685-
{
686-
std::cerr << __LINE__ << "\n";
687-
}
688660
}
689661
}

subprojects/phosphor-logging.wrap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-git]
2+
url = https://github.com/openbmc/phosphor-logging.git
3+
revision = HEAD
4+
5+
[provide]
6+
phosphor-logging = phosphor_logging_dep

subprojects/sdbusplus.wrap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[wrap-git]
22
url = https://github.com/openbmc/sdbusplus.git
33
revision = HEAD
4+
5+
[provide]
6+
sdbusplus = sdbusplus_dep

0 commit comments

Comments
 (0)