feat: enhance logging by changing info logs to debug level for detailed tracing

This commit is contained in:
whaffman 2025-09-30 11:26:05 +02:00
parent a3e9699eb9
commit d360728b18
5 changed files with 12 additions and 12 deletions

View File

@ -18,11 +18,12 @@
Client::Client(std::unique_ptr<Socket> socket, Server &server) Client::Client(std::unique_ptr<Socket> socket, Server &server)
: client_socket_(std::move(socket)), server_(std::ref(server)), httpRequest_(std::make_unique<HttpRequest>(this)) : client_socket_(std::move(socket)), server_(std::ref(server)), httpRequest_(std::make_unique<HttpRequest>(this))
{ {
Log::info("New client connected, fd: " + std::to_string(client_socket_->getFd()));
} }
Client::~Client() Client::~Client()
{ {
Log::debug("Client destructor called for fd: " + std::to_string(client_socket_->getFd())); Log::info("Client disconnected, fd: " + std::to_string(client_socket_->getFd()));
server_.removeFromEpoll(*client_socket_); server_.removeFromEpoll(*client_socket_);
}; };
@ -48,7 +49,7 @@ void Client::request()
} }
if (bytesRead == 0) if (bytesRead == 0)
{ {
Log::info("Client disconnected, fd: " + std::to_string(client_socket_->getFd())); Log::info("Client disconnected, fd: " + std::to_string(client_socket_->getFd())); //TODO weird
return; return;
} }
@ -102,7 +103,7 @@ std::string Client::getResponse() const
body += "Server port " + std::to_string(port) + "\r\n"; body += "Server port " + std::to_string(port) + "\r\n";
response += "Content-Length: " + std::to_string(body.size()) + "\r\n\r\n"; response += "Content-Length: " + std::to_string(body.size()) + "\r\n\r\n";
response += body; response += body;
Log::info("Prepared response for client fd: " + std::to_string(client_socket_->getFd()));
Log::debug("Sending response:\n" + response); Log::debug("Sending response:\n" + response);
return response; return response;
} }

View File

@ -64,7 +64,7 @@ void AConfig::parseDirectives(const std::string &declarations)
{ {
continue; continue;
} }
Log::info("Global Declaration: " + line); Log::debug("Global Declaration: " + line);
addDirective(line); addDirective(line);
} }
} }

View File

@ -28,7 +28,7 @@ void ConfigManager::init(const std::string &filePath)
Log::warning("ConfigManager is already initialized."); Log::warning("ConfigManager is already initialized.");
throw std::runtime_error("ConfigManager is already initialized."); throw std::runtime_error("ConfigManager is already initialized.");
} }
Log::info("Initializing ConfigManager with file: " + filePath); Log::debug("Initializing ConfigManager with file: " + filePath);
parseConfigFile(filePath); parseConfigFile(filePath);
initialized_ = true; initialized_ = true;
} }
@ -36,7 +36,7 @@ void ConfigManager::init(const std::string &filePath)
void ConfigManager::parseConfigFile(const std::string &filePath) void ConfigManager::parseConfigFile(const std::string &filePath)
{ {
// Placeholder for actual file parsing logic // Placeholder for actual file parsing logic
Log::info("Parsing configuration file: " + filePath); Log::debug("Parsing configuration file: " + filePath);
// Implement the parsing logic here // Implement the parsing logic here
std::ifstream file(filePath); std::ifstream file(filePath);

View File

@ -16,9 +16,8 @@ int main(int argc, char **argv)
return 1; return 1;
} }
Log::setFileChannel("webserv.log", std::ios_base::app, Log::Level::Trace); Log::setFileChannel("webserv.log", std::ios_base::app, Log::Level::Trace);
Log::setStdoutChannel(Log::Level::Trace); Log::setStdoutChannel(Log::Level::Info);
Log::info("\n======================\nStarting webserv...\n======================\n"); Log::info("\n======================\nStarting webserv...\n======================\n");
Log::warning("Testing context: " + LOCATION, {{"key1", "value1"}, {"key2", "value2"}});
ConfigManager::getInstance().init(argv[1]); // NOLINT ConfigManager::getInstance().init(argv[1]); // NOLINT
ConfigManager &configManager = ConfigManager::getInstance(); ConfigManager &configManager = ConfigManager::getInstance();
Log::info("ConfigManager initialized successfully."); Log::info("ConfigManager initialized successfully.");

View File

@ -166,7 +166,7 @@ void Server::handleRequest(struct epoll_event *event) const
void Server::responseReady(int client_fd) const void Server::responseReady(int client_fd) const
{ {
Log::info("Response ready for client fd: " + std::to_string(client_fd)); Log::debug("Response ready for client fd: " + std::to_string(client_fd));
struct epoll_event ev{}; struct epoll_event ev{};
ev.events = EPOLLOUT; ev.events = EPOLLOUT;
ev.data.fd = client_fd; ev.data.fd = client_fd;
@ -179,7 +179,7 @@ void Server::responseReady(int client_fd) const
void Server::eventLoop() void Server::eventLoop()
{ {
Log::info("Entering event loop..."); Log::info("Listening...");
const int MAX_EVENTS = 10; const int MAX_EVENTS = 10;
struct epoll_event events[MAX_EVENTS]; // NOLINT struct epoll_event events[MAX_EVENTS]; // NOLINT
while (true) while (true)
@ -209,7 +209,7 @@ void Server::eventLoop()
} }
else if ((event.events & EPOLLOUT) > 0) else if ((event.events & EPOLLOUT) > 0)
{ {
Log::info("Attempting to send data to fd: " + std::to_string(event.data.fd)); Log::debug("Attempting to send data to fd: " + std::to_string(event.data.fd));
Client &client = getClient(event.data.fd); Client &client = getClient(event.data.fd);
std::string response = client.getResponse(); std::string response = client.getResponse();
const char *httpResponse = response.c_str(); const char *httpResponse = response.c_str();
@ -221,7 +221,7 @@ void Server::eventLoop()
} }
else else
{ {
Log::info("Sent " + std::to_string(bytesSent) + " bytes to fd: " + std::to_string(event.data.fd)); Log::debug("Sent " + std::to_string(bytesSent) + " bytes to fd: " + std::to_string(event.data.fd));
} }
clients_.erase(event.data.fd); clients_.erase(event.data.fd);
} }