Replaced Logger usage with LOG_x (#548)
This commit is contained in:
committed by
GitHub
parent
ecad2248d9
commit
9d5993930d
@@ -1,10 +1,11 @@
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/network/Http.h>
|
||||
|
||||
#include "Tactility/service/gui/GuiService.h"
|
||||
|
||||
#include <tactility/log.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/network/EspHttpClient.h>
|
||||
#include <esp_http_client.h>
|
||||
@@ -12,7 +13,7 @@
|
||||
|
||||
namespace tt::network::http {
|
||||
|
||||
static const auto LOGGER = Logger("HTTP");
|
||||
constexpr auto* TAG = "HTTP";
|
||||
|
||||
void download(
|
||||
const std::string& url,
|
||||
@@ -22,10 +23,10 @@ void download(
|
||||
const std::function<void(const char* errorMessage)>& onError
|
||||
) {
|
||||
service::gui::warnIfRunningOnGuiTask("HTTP");
|
||||
LOGGER.info("Downloading from {} to {}", url, downloadFilePath);
|
||||
LOG_I(TAG, "Downloading from %s to %s", url.c_str(), downloadFilePath.c_str());
|
||||
#ifdef ESP_PLATFORM
|
||||
getMainDispatcher().dispatch([url, certFilePath, downloadFilePath, onSuccess, onError] {
|
||||
LOGGER.info("Loading certificate");
|
||||
LOG_I(TAG, "Loading certificate");
|
||||
auto certificate = file::readString(certFilePath);
|
||||
if (certificate == nullptr) {
|
||||
onError("Failed to read certificate");
|
||||
@@ -71,14 +72,14 @@ void download(
|
||||
|
||||
auto lock = file::getLock(downloadFilePath)->asScopedLock();
|
||||
lock.lock();
|
||||
LOGGER.info("opening {}", downloadFilePath);
|
||||
LOG_I(TAG, "opening %s", downloadFilePath.c_str());
|
||||
auto* file = fopen(downloadFilePath.c_str(), "wb");
|
||||
if (file == nullptr) {
|
||||
onError("Failed to open file");
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Writing {} bytes to {}", bytes_left, downloadFilePath);
|
||||
LOG_I(TAG, "Writing %d bytes to %s", bytes_left, downloadFilePath.c_str());
|
||||
char buffer[512];
|
||||
while (bytes_left > 0) {
|
||||
int data_read = client->read(buffer, 512);
|
||||
@@ -96,7 +97,7 @@ void download(
|
||||
taskYIELD();
|
||||
}
|
||||
fclose(file);
|
||||
LOGGER.info("Downloaded {} to {}", url, downloadFilePath);
|
||||
LOG_I(TAG, "Downloaded %s to %s", url.c_str(), downloadFilePath.c_str());
|
||||
onSuccess();
|
||||
});
|
||||
#else
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
#include <Tactility/network/HttpServer.h>
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
|
||||
#include <tactility/log.h>
|
||||
|
||||
namespace tt::network {
|
||||
|
||||
static const auto LOGGER = Logger("HttpServer");
|
||||
constexpr auto* TAG = "HttpServer";
|
||||
|
||||
static constexpr size_t INTERNAL_URI_HANDLER_COUNT = 2;
|
||||
|
||||
@@ -19,14 +20,14 @@ bool HttpServer::startInternal() {
|
||||
config.max_uri_handlers = handlers.size() + INTERNAL_URI_HANDLER_COUNT;
|
||||
|
||||
if (httpd_start(&server, &config) != ESP_OK) {
|
||||
LOGGER.error("Failed to start http server on port {}", port);
|
||||
LOG_E(TAG, "Failed to start http server on port %u", (unsigned)port);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool allRegistered = true;
|
||||
for (std::vector<httpd_uri_t>::reference handler : handlers) {
|
||||
if (httpd_register_uri_handler(server, &handler) != ESP_OK) {
|
||||
LOGGER.error("Failed to register URI handler: {}", handler.uri);
|
||||
LOG_E(TAG, "Failed to register URI handler: %s", handler.uri);
|
||||
allRegistered = false;
|
||||
}
|
||||
}
|
||||
@@ -36,17 +37,17 @@ bool HttpServer::startInternal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGGER.info("Started on port {}", config.server_port);
|
||||
LOG_I(TAG, "Started on port %u", (unsigned)config.server_port);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HttpServer::stopInternal() {
|
||||
LOGGER.info("Stopping server");
|
||||
LOG_I(TAG, "Stopping server");
|
||||
if (server != nullptr) {
|
||||
if (httpd_stop(server) == ESP_OK) {
|
||||
server = nullptr;
|
||||
} else {
|
||||
LOGGER.warn("Error while stopping");
|
||||
LOG_W(TAG, "Error while stopping");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +57,7 @@ bool HttpServer::start() {
|
||||
lock.lock();
|
||||
|
||||
if (isStarted()) {
|
||||
LOGGER.warn("Already started");
|
||||
LOG_W(TAG, "Already started");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ void HttpServer::stop() {
|
||||
lock.lock();
|
||||
|
||||
if (!isStarted()) {
|
||||
LOGGER.warn("Not started");
|
||||
LOG_W(TAG, "Not started");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include <Tactility/network/HttpdReq.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/network/HttpdReq.h>
|
||||
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <memory>
|
||||
#include <ranges>
|
||||
@@ -12,7 +13,7 @@
|
||||
|
||||
namespace tt::network {
|
||||
|
||||
static const auto LOGGER = Logger("HttpdReq");
|
||||
constexpr auto* TAG = "HttpdReq";
|
||||
|
||||
bool getHeaderOrSendError(httpd_req_t* request, const std::string& name, std::string& value) {
|
||||
size_t header_size = httpd_req_get_hdr_value_len(request, name.c_str());
|
||||
@@ -23,7 +24,7 @@ bool getHeaderOrSendError(httpd_req_t* request, const std::string& name, std::st
|
||||
|
||||
auto header_buffer = std::make_unique<char[]>(header_size + 1);
|
||||
if (header_buffer == nullptr) {
|
||||
LOGGER.error( LOG_MESSAGE_ALLOC_FAILED);
|
||||
LOG_E(TAG, LOG_MESSAGE_ALLOC_FAILED);
|
||||
httpd_resp_send_500(request);
|
||||
return false;
|
||||
}
|
||||
@@ -79,7 +80,7 @@ std::unique_ptr<char[]> receiveByteArray(httpd_req_t* request, size_t length, si
|
||||
// and we don't have exceptions enabled in the compiler settings
|
||||
auto* buffer = static_cast<char*>(malloc(length));
|
||||
if (buffer == nullptr) {
|
||||
LOGGER.error(LOG_MESSAGE_ALLOC_FAILED_FMT, length);
|
||||
LOG_E(TAG, "Out of memory (failed to allocated %u bytes)", (unsigned)length);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -92,16 +93,16 @@ std::unique_ptr<char[]> receiveByteArray(httpd_req_t* request, size_t length, si
|
||||
// Timeout - retry with backoff
|
||||
timeout_retries++;
|
||||
if (timeout_retries >= MAX_TIMEOUT_RETRIES) {
|
||||
LOGGER.warn("Recv timeout after {} retries, read {}/{} bytes", timeout_retries, bytesRead, length);
|
||||
LOG_W(TAG, "Recv timeout after %d retries, read %u/%u bytes", timeout_retries, (unsigned)bytesRead, (unsigned)length);
|
||||
free(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
LOGGER.warn("Recv timeout, retry {}/{}", timeout_retries, MAX_TIMEOUT_RETRIES);
|
||||
LOG_W(TAG, "Recv timeout, retry %d/%d", timeout_retries, MAX_TIMEOUT_RETRIES);
|
||||
vTaskDelay(pdMS_TO_TICKS(100 * timeout_retries)); // Exponential backoff
|
||||
continue;
|
||||
}
|
||||
if (bytes_received <= 0) {
|
||||
LOGGER.warn("Received error {} after reading {}/{} bytes", bytes_received, bytesRead, length);
|
||||
LOG_W(TAG, "Received error %d after reading %u/%u bytes", bytes_received, (unsigned)bytesRead, (unsigned)length);
|
||||
free(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -190,7 +191,7 @@ size_t receiveFile(httpd_req_t* request, size_t length, const std::string& fileP
|
||||
|
||||
auto* file = fopen(filePath.c_str(), "wb");
|
||||
if (file == nullptr) {
|
||||
LOGGER.error("Failed to open file for writing: {}", filePath);
|
||||
LOG_E(TAG, "Failed to open file for writing: %s", filePath.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -198,11 +199,11 @@ size_t receiveFile(httpd_req_t* request, size_t length, const std::string& fileP
|
||||
auto expected_chunk_size = std::min<size_t>(BUFFER_SIZE, length - bytes_received);
|
||||
size_t receive_chunk_size = httpd_req_recv(request, buffer, expected_chunk_size);
|
||||
if (receive_chunk_size <= 0) {
|
||||
LOGGER.error("Receive failed");
|
||||
LOG_E(TAG, "Receive failed");
|
||||
break;
|
||||
}
|
||||
if (fwrite(buffer, 1, receive_chunk_size, file) != (size_t)receive_chunk_size) {
|
||||
LOGGER.error("Failed to write all bytes");
|
||||
LOG_E(TAG, "Failed to write all bytes");
|
||||
break;
|
||||
}
|
||||
bytes_received += receive_chunk_size;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <Tactility/network/NtpPrivate.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Preferences.h>
|
||||
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@@ -13,7 +14,7 @@
|
||||
|
||||
namespace tt::network::ntp {
|
||||
|
||||
static const auto LOGGER = Logger("NTP");
|
||||
constexpr auto* TAG = "NTP";
|
||||
|
||||
static bool processedSyncEvent = false;
|
||||
|
||||
@@ -25,14 +26,14 @@ void storeTimeInNvs() {
|
||||
|
||||
auto preferences = std::make_unique<Preferences>("time");
|
||||
preferences->putInt64("syncTime", now);
|
||||
LOGGER.info("Stored time {}", now);
|
||||
LOG_I(TAG, "Stored time %ld", (long)now);
|
||||
}
|
||||
|
||||
void setTimeFromNvs() {
|
||||
auto preferences = std::make_unique<Preferences>("time");
|
||||
time_t synced_time;
|
||||
if (preferences->optInt64("syncTime", synced_time)) {
|
||||
LOGGER.info("Restoring last known time to {}", synced_time);
|
||||
LOG_I(TAG, "Restoring last known time to %ld", (long)synced_time);
|
||||
timeval get_nvs_time;
|
||||
get_nvs_time.tv_sec = synced_time;
|
||||
settimeofday(&get_nvs_time, nullptr);
|
||||
@@ -40,7 +41,7 @@ void setTimeFromNvs() {
|
||||
}
|
||||
|
||||
static void onTimeSynced(timeval* tv) {
|
||||
LOGGER.info("Time synced ({})", tv->tv_sec);
|
||||
LOG_I(TAG, "Time synced (%ld)", (long)tv->tv_sec);
|
||||
processedSyncEvent = true;
|
||||
esp_netif_sntp_deinit();
|
||||
storeTimeInNvs();
|
||||
|
||||
Reference in New Issue
Block a user