Skip to content

Commit

Permalink
feat: add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzafa8 committed Mar 19, 2024
1 parent d376398 commit e5450a4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
16 changes: 16 additions & 0 deletions includes/Logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef LOGGER_HPP
# define LOGGER_HPP

# include <iostream>
# include <string>

class Logger {
private:
Logger(void);
~Logger(void);

public:
static void debug(std::string message);
};

#endif
2 changes: 2 additions & 0 deletions includes/libsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

# include "exceptions.hpp"

# include "Logger.hpp"

// =================================================================================

# define SUCCESS 0
Expand Down
11 changes: 11 additions & 0 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
* @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;
}

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;
Expand Down

0 comments on commit e5450a4

Please sign in to comment.