diff --git a/includes/Logger.hpp b/includes/Logger.hpp new file mode 100644 index 0000000..368dd71 --- /dev/null +++ b/includes/Logger.hpp @@ -0,0 +1,16 @@ +#ifndef LOGGER_HPP +# define LOGGER_HPP + +# include +# include + +class Logger { + private: + Logger(void); + ~Logger(void); + + public: + static void debug(std::string message); +}; + +#endif \ No newline at end of file diff --git a/includes/libsUtils.hpp b/includes/libsUtils.hpp index 03a7cf2..f49d40d 100644 --- a/includes/libsUtils.hpp +++ b/includes/libsUtils.hpp @@ -16,6 +16,8 @@ # include "exceptions.hpp" +# include "Logger.hpp" + // ================================================================================= # define SUCCESS 0 diff --git a/src/Logger.cpp b/src/Logger.cpp new file mode 100644 index 0000000..aa70bc9 --- /dev/null +++ b/src/Logger.cpp @@ -0,0 +1,11 @@ +#include "Logger.hpp" + +Logger::Logger(void) {} + +Logger::~Logger(void) {} + +void Logger::debug(std::string message) { +#ifdef DEBUG + std::cout << "[DEBUG] " << message << std::endl; +#endif +} diff --git a/src/Server.cpp b/src/Server.cpp index 69d3244..27765f3 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -167,7 +167,7 @@ void Server::handleExistingConnection(int clientFd) { if (buffer[0] == '\0') return; - + Logger::debug("Mensaje del cliente: " + std::string(buffer, readBytes)); try { ICommand* command = CommandParser::parse(std::string(buffer, readBytes)); command->execute(*this, clientFd); diff --git a/src/main.cpp b/src/main.cpp index ab2edfe..de1d0cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,8 +16,7 @@ * @return `0` if the program ends successfully, `1` otherwise. */ int main(int argc, char **argv) { - if (argc != 3) - { + if (argc != 3) { std::cerr << INVALID_ARGS << std::endl; return EXIT; } @@ -25,7 +24,6 @@ int main(int argc, char **argv) { try { std::string port = std::string(argv[1]); std::string password = std::string(argv[2]); - Server server(port, password); } catch (ServerException& e) { std::cerr << e.what() << std::endl;