mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-27 13:52:14 +00:00
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:
1 parent
3babdc001d
commit
79b75bbd4e
35 files changed
+595
-604
No files matched your search
@@ -147,7 +147,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ERROR("file_exists: failed to open file " + std::string(file_path));
|
||||
ERRORF("file_exists: failed to open file %s", file_path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -181,9 +181,9 @@ public:
|
||||
//size_t read = fread(data.writable(size), size, 1, file);
|
||||
read = fread(data.writable(size), 1, size, file);
|
||||
#endif
|
||||
TRACE("read_file: read " + std::to_string(read) + " bytes from file " + std::string(file_path));
|
||||
TRACEF("read_file: read %zu bytes from file %s", read, file_path);
|
||||
if (read != size) {
|
||||
ERROR("read_file: failed to read file " + std::string(file_path));
|
||||
ERRORF("read_file: failed to read file %s", file_path);
|
||||
data.clear();
|
||||
}
|
||||
//TRACE("read_file: closing input file");
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
ERROR("read_file: failed to open input file " + std::string(file_path));
|
||||
ERRORF("read_file: failed to open input file %s", file_path);
|
||||
}
|
||||
return read;
|
||||
}
|
||||
@@ -227,9 +227,9 @@ public:
|
||||
//size_t wrote = fwrite(data.data(), data.size(), 1, file);
|
||||
wrote = fwrite(data.data(), 1, data.size(), file);
|
||||
#endif
|
||||
TRACE("write_file: wrote " + std::to_string(wrote) + " bytes to file " + std::string(file_path));
|
||||
TRACEF("write_file: wrote %zu bytes to file %s", wrote, file_path);
|
||||
if (wrote < data.size()) {
|
||||
WARNING("write_file: not all data was written to file " + std::string(file_path));
|
||||
WARNINGF("write_file: not all data was written to file %s", file_path);
|
||||
}
|
||||
//TRACE("write_file: closing output file");
|
||||
#ifdef ARDUINO
|
||||
@@ -244,7 +244,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
ERROR("write_file: failed to open output file " + std::string(file_path));
|
||||
ERRORF("write_file: failed to open output file %s", file_path);
|
||||
}
|
||||
return wrote;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public:
|
||||
}
|
||||
|
||||
/*virtua*/ bool directory_exists(const char* directory_path) {
|
||||
TRACE("directory_exists: checking for existence of directory " + std::string(directory_path));
|
||||
TRACEF("directory_exists: checking for existence of directory %s", directory_path);
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
File file = SPIFFS.open(directory_path, FILE_READ);
|
||||
@@ -409,13 +409,13 @@ public:
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
if (!SPIFFS.mkdir(directory_path)) {
|
||||
ERROR("create_directory: failed to create directorty " + std::string(directory_path));
|
||||
ERRORF("create_directory: failed to create directorty %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#elif BOARD_NRF52
|
||||
if (!InternalFS.mkdir(directory_path)) {
|
||||
ERROR("create_directory: failed to create directorty " + std::string(directory_path));
|
||||
ERRORF("create_directory: failed to create directorty %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -433,18 +433,18 @@ public:
|
||||
}
|
||||
|
||||
/*virtua*/ bool remove_directory(const char* directory_path) {
|
||||
TRACE("remove_directory: removing directory " + std::string(directory_path));
|
||||
TRACEF("remove_directory: removing directory %s", directory_path);
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
//if (!LittleFS.rmdir_r(directory_path)) {
|
||||
if (!SPIFFS.rmdir(directory_path)) {
|
||||
ERROR("remove_directory: failed to remove directorty " + std::string(directory_path));
|
||||
ERRORF("remove_directory: failed to remove directorty %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#elif BOARD_NRF52
|
||||
if (!InternalFS.rmdir_r(directory_path)) {
|
||||
ERROR("remove_directory: failed to remove directory " + std::string(directory_path));
|
||||
ERRORF("remove_directory: failed to remove directory %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -454,7 +454,7 @@ public:
|
||||
#else
|
||||
// Native
|
||||
if (rmdir(directory_path) == 0) {
|
||||
ERROR("remove_directory: failed to remove directory " + std::string(directory_path));
|
||||
ERRORF("remove_directory: failed to remove directory %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -462,7 +462,7 @@ public:
|
||||
}
|
||||
|
||||
/*virtua*/ std::list<std::string> list_directory(const char* directory_path) {
|
||||
TRACE("list_directory: listing directory " + std::string(directory_path));
|
||||
TRACEF("list_directory: listing directory %s", directory_path);
|
||||
std::list<std::string> files;
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
@@ -471,7 +471,7 @@ public:
|
||||
File root = InternalFS.open(directory_path);
|
||||
#endif
|
||||
if (!root) {
|
||||
ERROR("list_directory: failed to open directory " + std::string(directory_path));
|
||||
ERRORF("list_directory: failed to open directory %s", directory_path);
|
||||
return files;
|
||||
}
|
||||
File file = root.openNextFile();
|
||||
@@ -491,7 +491,7 @@ public:
|
||||
// Native
|
||||
DIR *dir = opendir(directory_path);
|
||||
if (dir == NULL) {
|
||||
ERROR("list_directory: failed to open directory " + std::string(directory_path));
|
||||
ERRORF("list_directory: failed to open directory %s", directory_path);
|
||||
return files;
|
||||
}
|
||||
struct dirent *entry;
|
||||
@@ -503,7 +503,7 @@ public:
|
||||
files.push_back(name);
|
||||
}
|
||||
if (closedir(dir) == -1) {
|
||||
ERROR("list_directory: failed to close directory " + std::string(directory_path));
|
||||
ERRORF("list_directory: failed to close directory %s", directory_path);
|
||||
}
|
||||
|
||||
return files;
|
||||
|
||||
Reference in new issue
Block a user