Skip to content

Commit

Permalink
chore(debug): overload log function so that it takes colors
Browse files Browse the repository at this point in the history
  • Loading branch information
552020 committed May 23, 2024
1 parent 59fb09f commit 8c917ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/Debug.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Debug.hpp"
#include "webserv.hpp"

// In C++98 the initialization of static members must be done outside the class definition.
bool Debug::debugEnabled = true;
Expand Down Expand Up @@ -38,14 +39,19 @@ void Debug::removeLevel(Debug::Level level)
debugLevel = static_cast<Debug::Level>(debugLevel & ~level);
}

void Debug::log(const std::string &message, Debug::Level paramLevel)
void Debug::log(const std::string &message, Debug::Level paramLevel, const std::string &color)
{
if (!debugEnabled)
{
return;
}
if (debugLevel & paramLevel)
{
std::cout << message << std::endl;
std::cout << color << message << "\033[0m" << std::endl;
}
}

void Debug::log(const std::string &message, Debug::Level paramLevel)
{
log(message, paramLevel, RESET);
}
1 change: 1 addition & 0 deletions src/Debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Debug
static void addLevel(Level level);
static void removeLevel(Level leve);
static void log(const std::string &message, Debug::Level paramLevel);
static void log(const std::string &message, Debug::Level paramLevel, const std::string &color);
};

#endif
2 changes: 1 addition & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ void Server::addServerSocketsPollFdToVectors()
void Server::acceptNewConnection(Connection &conn)
{

// printFrame("SERVER SOCKET EVENT", true);
printFrame("SERVER SOCKET EVENT", true);
struct sockaddr_storage clientAddress;
socklen_t ClientAddrLen = sizeof(clientAddress);
Debug::log("New connection detected", Debug::SERVER);
Expand Down

0 comments on commit 8c917ca

Please sign in to comment.