Replace string-concatenation logging with printf-style F-variants

Converted log calls across src/, examples/, and test/ to use DEBUGF/TRACEF/ERRORF/etc. macros instead of std::string + operator+. This eliminates temporary heap allocations on every log call, which matters on memory-constrained MCUs.
This commit is contained in:
Chad Attermann committed 2026-03-01 10:59:33 -07:00
1 parent 3babdc001d
commit 79b75bbd4e
35 files changed
+595 -604

No files matched your search

+11 -11
View File
@@ -36,7 +36,7 @@ public:
_name = "(deleted)";
}
virtual void send_outgoing(const RNS::Bytes &data) {
HEAD("OutInterface.send_outgoing: data: " + data.toHex(), RNS::LOG_TRACE);
HEADF(RNS::LOG_TRACE, "OutInterface.send_outgoing: data: %s", data.toHex().c_str());
// Loop data back to InInterface for testing
// NOTE: This sends the incoming data directory to RNS::Interface (which relays to Transport)
@@ -57,13 +57,13 @@ public:
virtual ~ExampleAnnounceHandler() {}
virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) {
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex());
INFOF("ExampleAnnounceHandler: destination hash: %s", destination_hash.toHex().c_str());
if (announced_identity) {
INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex());
INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex());
INFOF("ExampleAnnounceHandler: announced identity hash: %s", announced_identity.hash().toHex().c_str());
INFOF("ExampleAnnounceHandler: announced identity app data: %s", announced_identity.app_data().toHex().c_str());
}
if (app_data) {
INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\"");
INFOF("ExampleAnnounceHandler: app data text: \"%s\"", app_data.toString().c_str());
}
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -77,9 +77,9 @@ RNS::HAnnounceHandler announce_handler(new ExampleAnnounceHandler());
//void(*)(const Bytes& data, const Packet& packet)
void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
INFO("onPacket: data: " + data.toHex());
INFO("onPacket: text: \"" + data.toString() + "\"");
//TRACE("onPacket: " + packet.debugString());
INFOF("onPacket: data: %s", data.toHex().c_str());
INFOF("onPacket: text: \"%s\"", data.toString().c_str());
//TRACEF("onPacket: %s", packet.debugString().c_str());
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@@ -87,9 +87,9 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
//void(*)(const Bytes& data, const Packet& packet)
void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
INFO("onPingPacket: data: " + data.toHex());
INFO("onPingPacket: text: \"" + data.toString() + "\"");
//TRACE("onPingPacket: " + packet.debugString());
INFOF("onPingPacket: data: %s", data.toHex().c_str());
INFOF("onPingPacket: text: \"%s\"", data.toString().c_str());
//TRACEF("onPingPacket: %s", packet.debugString().c_str());
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}