Skip to content

Commit

Permalink
Merge pull request #31 from jdomingu98/30-logger
Browse files Browse the repository at this point in the history
Logger
  • Loading branch information
ruzafa8 authored Mar 22, 2024
2 parents d376398 + f13e5f3 commit 2ba7c50
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PARSER_PREFIXS = Command User Pass Nick Quit
PARSER_FILES = $(addsuffix Parser, $(PARSER_PREFIXS))
PARSER_SRCS = $(addprefix $(PARSER_DIR), $(PARSER_FILES))

FILES = main Server User Channel utils
FILES = main Server User Channel utils Logger

SRCS_PATHS = $(addprefix $(SRC_DIR)/, $(FILES)) $(CMD_SRCS) $(PARSER_SRCS)
SRCS = $(addsuffix .cpp, $(SRCS_PATHS))
Expand Down
18 changes: 18 additions & 0 deletions includes/Logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef LOGGER_HPP
# define LOGGER_HPP

# include <iostream>
# include <string>

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

static const bool _debugMode = true;

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
10 changes: 10 additions & 0 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Logger.hpp"

Logger::Logger(void) {}

Logger::~Logger(void) {}

void Logger::debug(std::string message) {
if (Logger::_debugMode)
std::cout << "[DEBUG] " << message << std::endl;
}
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 2ba7c50

Please sign in to comment.