From d091879773d762d2b4ce30cfaa589ed270b49f93 Mon Sep 17 00:00:00 2001 From: homeburger Date: Thu, 23 Jul 2026 22:41:47 -0500 Subject: [PATCH] tweaks to make work --- client/src/TcpClient.cpp | 12 +++++++++--- common/LoggerService.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/src/TcpClient.cpp b/client/src/TcpClient.cpp index c3c42ff..a507951 100644 --- a/client/src/TcpClient.cpp +++ b/client/src/TcpClient.cpp @@ -1,6 +1,8 @@ #include "TcpClient.hpp" +#include + TcpClient::TcpClient(ConfigService* config, LoggerService* logger) : TcpBase(logger) { if(!(config->getConfig("TcpClient", "main", &configuration_))) { @@ -33,7 +35,7 @@ ErrorCode TcpClient::init() { // parse the hostname string into uint8s host = gethostbyname(configuration_.hostname.c_str()); if(host == NULL) { - logger_->log("TcpClient", LogFlag::Debug, "Unable to parse hostname."); + logger_->log("TcpClient", LogFlag::Error, "Unable to parse hostname."); close(socketFd_); // TODO: probably on a destructor return ErrorCode::Error; } @@ -41,7 +43,7 @@ ErrorCode TcpClient::init() { // create tcp socket socketFd_ = socket(AF_INET, SOCK_STREAM, 0); if(socketFd_ < 0) { - logger_->log("TcpClient", LogFlag::Debug, "Unable to open client socket."); + logger_->log("TcpClient", LogFlag::Error, "Unable to open client socket."); close(socketFd_); return ErrorCode::Error; } @@ -52,9 +54,13 @@ ErrorCode TcpClient::init() { serverAddress.sin_port = htons(configuration_.port); serverAddress.sin_addr = *((struct in_addr*)host->h_addr); + char ip[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, host->h_addr_list[0], ip, sizeof(ip)); + logger_->log("TcpClient", LogFlag::Error, "Connecting to {}:{}", ip, configuration_.port); + // connect to server if(connect(socketFd_, (struct sockaddr*)&serverAddress, sizeof(struct sockaddr)) < 0) { - logger_->log("TcpClient", LogFlag::Debug, "Unable to connect to server."); + logger_->log("TcpClient", LogFlag::Error, "Unable to connect to server."); close(socketFd_); return ErrorCode::Error; } diff --git a/common/LoggerService.cpp b/common/LoggerService.cpp index b606ef9..d395687 100644 --- a/common/LoggerService.cpp +++ b/common/LoggerService.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include namespace fs = std::filesystem; @@ -79,7 +81,7 @@ void LoggerService::write(std::string component, LogFlag flag, std::string messa std::string componentTrace = "[" + configuration_.id + ": " + component + "] "; finalmessage += componentTrace; // component is the section of the program (For example Mesh or Engine) that is calling the logger - + std::string level = ""; level = LogFlagStrings[flag]; @@ -87,6 +89,9 @@ void LoggerService::write(std::string component, LogFlag flag, std::string messa // level.append(7 - level.length(), ' ') pads out the level string with whitespace so every line is aligned the sam finalmessage = finalmessage + "[" + level + "] "; finalmessage = finalmessage + message + " "; + if(flag == LogFlag::Error) { + finalmessage += std::format("[errno = {} ({})]", errno, std::strerror(errno)); + } /* Removed because didn't want to bother with variadics + default arguments if (configuration_.showSourceTrace) {