Replaced Logger usage with LOG_x (#548)

This commit is contained in:
Ken Van Hoeylandt
2026-07-04 23:49:19 +02:00
committed by GitHub
parent ecad2248d9
commit 9d5993930d
162 changed files with 1776 additions and 1842 deletions
+9 -9
View File
@@ -1,6 +1,6 @@
#include <Tactility/crypt/Crypt.h>
#include <Tactility/Logger.h>
#include <tactility/log.h>
#include <tactility/check.h>
#include <mbedtls/aes.h>
@@ -15,7 +15,7 @@
namespace tt::crypt {
static const auto LOGGER = Logger("Crypt");
constexpr auto* TAG = "Crypt";
#define TT_NVS_NAMESPACE "tt_secure"
@@ -28,7 +28,7 @@ static void get_hardware_key(uint8_t key[32]) {
uint8_t mac[8];
// MAC can be 6 or 8 bytes
size_t mac_length = esp_mac_addr_len_get(ESP_MAC_EFUSE_FACTORY);
LOGGER.info("Using MAC with length {}", mac_length);
LOG_I(TAG, "Using MAC with length %u", (unsigned)mac_length);
check(mac_length <= 8);
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
@@ -67,13 +67,13 @@ static void get_nvs_key(uint8_t key[32]) {
esp_err_t result = nvs_open(TT_NVS_NAMESPACE, NVS_READWRITE, &handle);
if (result != ESP_OK) {
LOGGER.error("Failed to get key from NVS ({})", esp_err_to_name(result));
LOG_E(TAG, "Failed to get key from NVS (%s)", esp_err_to_name(result));
check(false, "NVS error");
}
size_t length = 32;
if (nvs_get_blob(handle, "key", key, &length) == ESP_OK) {
LOGGER.info("Fetched key from NVS ({} bytes)", length);
LOG_I(TAG, "Fetched key from NVS (%u bytes)", (unsigned)length);
check(length == 32);
} else {
// TODO: Improved randomness
@@ -84,7 +84,7 @@ static void get_nvs_key(uint8_t key[32]) {
key[i] = (uint8_t)(rand());
}
ESP_ERROR_CHECK(nvs_set_blob(handle, "key", key, 32));
LOGGER.info("Stored new key in NVS");
LOG_I(TAG, "Stored new key in NVS");
}
nvs_close(handle);
@@ -110,8 +110,8 @@ static void xorKey(const uint8_t* inLeft, const uint8_t* inRight, uint8_t* out,
*/
static void getKey(uint8_t key[32]) {
#if !defined(CONFIG_SECURE_BOOT) || !defined(CONFIG_SECURE_FLASH_ENC_ENABLED)
LOGGER.warn("Using tt_secure_* code with secure boot and/or flash encryption disabled.");
LOGGER.warn("An attacker with physical access to your ESP32 can decrypt your secure data.");
LOG_W(TAG, "Using tt_secure_* code with secure boot and/or flash encryption disabled.");
LOG_W(TAG, "An attacker with physical access to your ESP32 can decrypt your secure data.");
#endif
#ifdef ESP_PLATFORM
@@ -122,7 +122,7 @@ static void getKey(uint8_t key[32]) {
get_nvs_key(nvs_key);
xorKey(hardware_key, nvs_key, key, 32);
#else
LOGGER.warn("Using unsafe key for debugging purposes.");
LOG_W(TAG, "Using unsafe key for debugging purposes.");
memset(key, 0, 32);
#endif
}
+23 -23
View File
@@ -4,7 +4,7 @@
#include <fstream>
#include <unistd.h>
#include <Tactility/Logger.h>
#include <tactility/log.h>
#include <Tactility/StringUtils.h>
namespace tt::hal::sdcard {
@@ -13,7 +13,7 @@ class SdCardDevice;
namespace tt::file {
static const auto LOGGER = Logger("file");
constexpr auto* TAG = "file";
class NoLock final : public Lock {
bool lock(TickType_t timeout) const override { return true; }
@@ -25,7 +25,7 @@ static std::function<std::shared_ptr<Lock>(const std::string&)> findLockFunction
std::shared_ptr<Lock> getLock(const std::string& path) {
if (findLockFunction == nullptr) {
LOGGER.warn("File lock function not set!");
LOG_W(TAG, "File lock function not set!");
return noLock;
}
@@ -71,10 +71,10 @@ bool listDirectory(
auto lock = getLock(path)->asScopedLock();
lock.lock();
LOGGER.info("listDir start {}", path);
LOG_I(TAG, "listDir start %s", path.c_str());
DIR* dir = opendir(path.c_str());
if (dir == nullptr) {
LOGGER.error("Failed to open dir {}", path);
LOG_E(TAG, "Failed to open dir %s", path.c_str());
return false;
}
@@ -85,7 +85,7 @@ bool listDirectory(
closedir(dir);
LOGGER.info("listDir stop {}", path);
LOG_I(TAG, "listDir stop %s", path.c_str());
return true;
}
@@ -98,10 +98,10 @@ int scandir(
auto lock = getLock(path)->asScopedLock();
lock.lock();
LOGGER.info("scandir start");
LOG_I(TAG, "scandir start");
DIR* dir = opendir(path.c_str());
if (dir == nullptr) {
LOGGER.error("Failed to open dir {}", path);
LOG_E(TAG, "Failed to open dir %s", path.c_str());
return -1;
}
@@ -118,7 +118,7 @@ int scandir(
std::ranges::sort(outList, sortMethod);
}
LOGGER.info("scandir finish");
LOG_I(TAG, "scandir finish");
return outList.size();
}
@@ -127,18 +127,18 @@ long getSize(FILE* file) {
long original_offset = ftell(file);
if (fseek(file, 0, SEEK_END) != 0) {
LOGGER.error("fseek failed");
LOG_E(TAG, "fseek failed");
return -1;
}
long file_size = ftell(file);
if (file_size == -1) {
LOGGER.error("Could not get file length");
LOG_E(TAG, "Could not get file length");
return -1;
}
if (fseek(file, original_offset, SEEK_SET) != 0) {
LOGGER.error("fseek Failed");
LOG_E(TAG, "fseek Failed");
return -1;
}
@@ -154,26 +154,26 @@ static std::unique_ptr<uint8_t[]> readBinaryInternal(const std::string& filepath
FILE* file = fopen(filepath.c_str(), "rb");
if (file == nullptr) {
LOGGER.error("Failed to open {}", filepath);
LOG_E(TAG, "Failed to open %s", filepath.c_str());
return nullptr;
}
long content_length = getSize(file);
if (content_length == -1) {
LOGGER.error("Failed to determine content length for {}", filepath);
LOG_E(TAG, "Failed to determine content length for %s", filepath.c_str());
return nullptr;
}
auto data = std::make_unique<uint8_t[]>(content_length + sizePadding);
if (data == nullptr) {
LOGGER.error("Insufficient memory. Failed to allocate {} bytes.", content_length);
LOG_E(TAG, "Insufficient memory. Failed to allocate %ld bytes.", content_length);
return nullptr;
}
size_t buffer_offset = 0;
while (buffer_offset < content_length) {
size_t bytes_read = fread(&data.get()[buffer_offset], 1, content_length - buffer_offset, file);
LOGGER.debug("Read {} bytes", bytes_read);
LOG_D(TAG, "Read %u bytes", (unsigned)bytes_read);
if (bytes_read > 0) {
buffer_offset += bytes_read;
} else { // Something went wrong?
@@ -270,7 +270,7 @@ bool findOrCreateDirectory(const std::string& path, mode_t mode) {
if (path.empty()) {
return true;
}
LOGGER.debug("findOrCreate: {} {}", path, mode);
LOG_D(TAG, "findOrCreate: %s %u", path.c_str(), (unsigned)mode);
const char separator_to_find[] = {SEPARATOR, 0x00};
auto first_index = path[0] == SEPARATOR ? 1 : 0;
@@ -282,10 +282,10 @@ bool findOrCreateDirectory(const std::string& path, mode_t mode) {
auto to_create = is_last_segment ? path : path.substr(0, separator_index);
should_break = is_last_segment;
if (!findOrCreateDirectoryInternal(to_create, mode)) {
LOGGER.error("Failed to create {}", to_create);
LOG_E(TAG, "Failed to create %s", to_create.c_str());
return false;
} else {
LOGGER.debug(" - got: {}", to_create);
LOG_D(TAG, " - got: %s", to_create.c_str());
}
// Find next file separator index
@@ -311,7 +311,7 @@ bool deleteRecursively(const std::string& path) {
if (isDirectory(path)) {
std::vector<dirent> entries;
if (scandir(path, entries) < 0) {
LOGGER.error("Failed to scan directory {}", path);
LOG_E(TAG, "Failed to scan directory %s", path.c_str());
return false;
}
@@ -321,16 +321,16 @@ bool deleteRecursively(const std::string& path) {
return false;
}
}
LOGGER.info("Deleting {}", path);
LOG_I(TAG, "Deleting %s", path.c_str());
return deleteDirectory(path);
} else if (isFile(path)) {
LOGGER.info("Deleting {}", path);
LOG_I(TAG, "Deleting %s", path.c_str());
return deleteFile(path);
} else if (path == "/" || path == "." || path == "..") {
// No-op
return true;
} else {
LOGGER.error("Failed to delete \"{}\": unknown type", path);
LOG_E(TAG, "Failed to delete \"%s\": unknown type", path.c_str());
return false;
}
}