Replaced Logger usage with LOG_x (#548)
This commit is contained in:
committed by
GitHub
parent
ecad2248d9
commit
9d5993930d
@@ -2,43 +2,43 @@
|
||||
#include <Tactility/file/ObjectFilePrivate.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
static const auto LOGGER = Logger("ObjectFileReader");
|
||||
constexpr auto* TAG = "ObjectFileReader";
|
||||
|
||||
bool ObjectFileReader::open() {
|
||||
auto opening_file = std::unique_ptr<FILE, FileCloser>(fopen(filePath.c_str(), "r"));
|
||||
if (opening_file == nullptr) {
|
||||
LOGGER.error("Failed to open file {}", filePath.c_str());
|
||||
LOG_E(TAG, "Failed to open file %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
FileHeader file_header;
|
||||
if (fread(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
|
||||
LOGGER.error("Failed to read file header from {}", filePath);
|
||||
LOG_E(TAG, "Failed to read file header from %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_header.identifier != OBJECT_FILE_IDENTIFIER) {
|
||||
LOGGER.error("Invalid file type for {}", filePath);
|
||||
LOG_E(TAG, "Invalid file type for %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_header.version != OBJECT_FILE_VERSION) {
|
||||
LOGGER.error("Unknown version for {}: {}", filePath, file_header.identifier);
|
||||
LOG_E(TAG, "Unknown version for %s: %u", filePath.c_str(), (unsigned)file_header.identifier);
|
||||
return false;
|
||||
}
|
||||
|
||||
ContentHeader content_header;
|
||||
if (fread(&content_header, sizeof(ContentHeader), 1, opening_file.get()) != 1) {
|
||||
LOGGER.error("Failed to read content header from {}", filePath);
|
||||
LOG_E(TAG, "Failed to read content header from %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recordSize != content_header.recordSize) {
|
||||
LOGGER.error("Record size mismatch for {}: expected {}, got {}", filePath, recordSize, content_header.recordSize);
|
||||
LOG_E(TAG, "Record size mismatch for %s: expected %u, got %u", filePath.c_str(), (unsigned)recordSize, (unsigned)content_header.recordSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ bool ObjectFileReader::open() {
|
||||
|
||||
file = std::move(opening_file);
|
||||
|
||||
LOGGER.debug("File version: {}", file_header.version);
|
||||
LOGGER.debug("Content: version = {}, size = {} bytes, count = {}", content_header.recordVersion, content_header.recordSize, content_header.recordCount);
|
||||
LOG_D(TAG, "File version: %u", (unsigned)file_header.version);
|
||||
LOG_D(TAG, "Content: version = %u, size = %u bytes, count = %u", (unsigned)content_header.recordVersion, (unsigned)content_header.recordSize, (unsigned)content_header.recordCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ void ObjectFileReader::close() {
|
||||
|
||||
bool ObjectFileReader::readNext(void* output) {
|
||||
if (file == nullptr) {
|
||||
LOGGER.error("File not open");
|
||||
LOG_E(TAG, "File not open");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#include <Tactility/file/ObjectFile.h>
|
||||
#include <Tactility/file/ObjectFilePrivate.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
static const auto LOGGER = Logger("ObjectFileWriter");
|
||||
constexpr auto* TAG = "ObjectFileWriter";
|
||||
|
||||
bool ObjectFileWriter::open() {
|
||||
bool edit_existing = append && access(filePath.c_str(), F_OK) == 0;
|
||||
if (append && !edit_existing) {
|
||||
LOGGER.warn("access() to {} failed: {}", filePath, strerror(errno));
|
||||
LOG_W(TAG, "access() to %s failed: %s", filePath.c_str(), strerror(errno));
|
||||
}
|
||||
|
||||
// Edit existing or create a new file
|
||||
auto opening_file = std::unique_ptr<FILE, FileCloser>(std::fopen(filePath.c_str(), edit_existing ? "rb+" : "wb"));
|
||||
if (opening_file == nullptr) {
|
||||
LOGGER.error("Failed to open file {}", filePath);
|
||||
LOG_E(TAG, "Failed to open file %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ bool ObjectFileWriter::open() {
|
||||
|
||||
FileHeader file_header;
|
||||
if (fread(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
|
||||
LOGGER.error("Failed to read file header from {}", filePath);
|
||||
LOG_E(TAG, "Failed to read file header from %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_header.identifier != OBJECT_FILE_IDENTIFIER) {
|
||||
LOGGER.error("Invalid file type for {}", filePath);
|
||||
LOG_E(TAG, "Invalid file type for %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_header.version != OBJECT_FILE_VERSION) {
|
||||
LOGGER.error("Unknown version for {}: {}", filePath, file_header.version);
|
||||
LOG_E(TAG, "Unknown version for %s: %u", filePath.c_str(), (unsigned)file_header.version);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,17 +47,17 @@ bool ObjectFileWriter::open() {
|
||||
|
||||
ContentHeader content_header;
|
||||
if (fread(&content_header, sizeof(ContentHeader), 1, opening_file.get()) != 1) {
|
||||
LOGGER.error("Failed to read content header from {}", filePath);
|
||||
LOG_E(TAG, "Failed to read content header from %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recordSize != content_header.recordSize) {
|
||||
LOGGER.error("Record size mismatch for {}: expected {}, got {}", filePath, recordSize, content_header.recordSize);
|
||||
LOG_E(TAG, "Record size mismatch for %s: expected %u, got %u", filePath.c_str(), (unsigned)recordSize, (unsigned)content_header.recordSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recordVersion != content_header.recordVersion) {
|
||||
LOGGER.error("Version mismatch for {}: expected {}, got {}", filePath, recordVersion, content_header.recordVersion);
|
||||
LOG_E(TAG, "Version mismatch for %s: expected %u, got %u", filePath.c_str(), (unsigned)recordVersion, (unsigned)content_header.recordVersion);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ bool ObjectFileWriter::open() {
|
||||
} else {
|
||||
FileHeader file_header;
|
||||
if (fwrite(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
|
||||
LOGGER.error("Failed to write file header for {}", filePath);
|
||||
LOG_E(TAG, "Failed to write file header for %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ bool ObjectFileWriter::open() {
|
||||
|
||||
void ObjectFileWriter::close() {
|
||||
if (file == nullptr) {
|
||||
LOGGER.error("File not opened: {}", filePath);
|
||||
LOG_E(TAG, "File not opened: %s", filePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (fseek(file.get(), sizeof(FileHeader), SEEK_SET) != 0) {
|
||||
LOGGER.error("File seek failed: {}", filePath);
|
||||
LOG_E(TAG, "File seek failed: %s", filePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void ObjectFileWriter::close() {
|
||||
};
|
||||
|
||||
if (fwrite(&content_header, sizeof(ContentHeader), 1, file.get()) != 1) {
|
||||
LOGGER.error("Failed to write content header to {}", filePath);
|
||||
LOG_E(TAG, "Failed to write content header to %s", filePath.c_str());
|
||||
}
|
||||
|
||||
file = nullptr;
|
||||
@@ -105,12 +105,12 @@ void ObjectFileWriter::close() {
|
||||
|
||||
bool ObjectFileWriter::write(void* data) {
|
||||
if (file == nullptr) {
|
||||
LOGGER.error("File not opened: {}", filePath);
|
||||
LOG_E(TAG, "File not opened: %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fwrite(data, recordSize, 1, file.get()) != 1) {
|
||||
LOGGER.error("Failed to write record to {}", filePath);
|
||||
LOG_E(TAG, "Failed to write record to %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/FileLock.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
static const auto LOGGER = Logger("PropertiesFile");
|
||||
constexpr auto* TAG = "PropertiesFile";
|
||||
|
||||
bool getKeyValuePair(const std::string& input, std::string& key, std::string& value) {
|
||||
auto index = input.find('=');
|
||||
@@ -22,7 +22,7 @@ bool getKeyValuePair(const std::string& input, std::string& key, std::string& va
|
||||
bool loadPropertiesFile(const std::string& filePath, std::function<void(const std::string& key, const std::string& value)> callback) {
|
||||
// Reading properties is a common operation; make this debug-level to avoid
|
||||
// flooding the serial console under frequent polling.
|
||||
LOGGER.debug("Reading properties file {}", filePath);
|
||||
LOG_D(TAG, "Reading properties file %s", filePath.c_str());
|
||||
uint16_t line_count = 0;
|
||||
std::string key_prefix = "";
|
||||
// Malformed lines are skipped, valid lines are loaded and callback is called
|
||||
@@ -40,7 +40,7 @@ bool loadPropertiesFile(const std::string& filePath, std::function<void(const st
|
||||
std::string trimmed_value = string::trim(value, " \t");
|
||||
callback(trimmed_key, trimmed_value);
|
||||
} else {
|
||||
LOGGER.error("Failed to parse line {} of {} (skipped)", line_count, filePath);
|
||||
LOG_E(TAG, "Failed to parse line %d of %s (skipped)", line_count, filePath.c_str());
|
||||
// Continue loading other lines
|
||||
}
|
||||
}
|
||||
@@ -57,11 +57,11 @@ bool loadPropertiesFile(const std::string& filePath, std::map<std::string, std::
|
||||
bool savePropertiesFile(const std::string& filePath, const std::map<std::string, std::string>& properties) {
|
||||
bool result = false;
|
||||
getLock(filePath)->withLock([&result, filePath, &properties] {
|
||||
LOGGER.info("Saving properties file {}", filePath);
|
||||
LOG_I(TAG, "Saving properties file %s", filePath.c_str());
|
||||
|
||||
FILE* file = fopen(filePath.c_str(), "w");
|
||||
if (file == nullptr) {
|
||||
LOGGER.error("Failed to open {}", filePath);
|
||||
LOG_E(TAG, "Failed to open %s", filePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user