Skip to content

Commit

Permalink
feat(Logger): Add Logger class to Flakkari namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterLaplace committed Dec 20, 2023
1 parent 9a937c9 commit b53fc28
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 60 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ project(R-Type_Server)
# Add all your source and headers files:
set(SOURCES
Flakkari/core.cpp
Flakkari/Logger/Logger.cpp
)

set(HEADERS
Flakkari/FlakkariLogger.hpp
Flakkari/Logger/Logger.hpp
)

# Separate Build Artifacts:
Expand Down
67 changes: 8 additions & 59 deletions Flakkari/FlakkariLogger.hpp → Flakkari/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,14 @@
** EPITECH PROJECT, 2023
** Flakkari
** File description:
** Flakkari::Logger
** Logger
*/

#ifndef FLAKKARI_LOGGER_HPP_
#define FLAKKARI_LOGGER_HPP_

#define LOG_INFO 0
#define LOG_LOG 1
#define LOG_DEBUG 2
#define LOG_WARNING 3
#define LOG_ERROR 4
#define LOG_FATAL 5

#include <iostream>
#include <string>
#include <chrono>
#include <ctime>

#define FLAKKARI_LOG(level, message) Flakkari::Logger::log(level, message, __FILE__, __LINE__)
#define FLAKKARI_LOG_INFO(message) FLAKKARI_LOG(LOG_INFO, message)
#define FLAKKARI_LOG_LOG(message) FLAKKARI_LOG(LOG_LOG, message)
#define FLAKKARI_LOG_DEBUG(message) FLAKKARI_LOG(LOG_DEBUG, message)
#define FLAKKARI_LOG_WARNING(message) FLAKKARI_LOG(LOG_WARNING, message)
#define FLAKKARI_LOG_ERROR(message) FLAKKARI_LOG(LOG_ERROR, message)
#define FLAKKARI_LOG_FATAL(message) FLAKKARI_LOG(LOG_FATAL, message)

#define COLOR_RESET "\033[0m"
#define COLOR_RED "\033[31m"
#define COLOR_GREEN "\033[32m"
#define COLOR_YELLOW "\033[33m"
#define COLOR_BLUE "\033[34m"
#define COLOR_MAGENTA "\033[35m"
#define COLOR_CYAN "\033[36m"
#define COLOR_WHITE "\033[37m"
#define COLOR_ORANGE "\033[38;5;208m"
#define COLOR_BRIGHT_RED "\033[91m"
#define COLOR_BRIGHT_GREEN "\033[92m"
#define COLOR_BRIGHT_YELLOW "\033[93m"
#define COLOR_BRIGHT_BLUE "\033[94m"
#define COLOR_BRIGHT_MAGENTA "\033[95m"
#define COLOR_BRIGHT_CYAN "\033[96m"
#define COLOR_BRIGHT_WHITE "\033[97m"
#include "Logger.hpp"

namespace Flakkari {
class Logger {
public:
static const std::string get_current_time() noexcept;
static void log(int level, std::string message, std::string file, int line);
static void log(int level, std::string message);
static void log(int level, std::string message, std::string file);
static void log(int level, std::string message, int line);
};
} // namespace Flakkari

#endif /* !FLAKKARI_LOGGER_HPP_ */

#ifdef FLAKKARI_LOGGER_IMPLEMENTATION

const std::string Flakkari::Logger::get_current_time() noexcept
const std::string Logger::get_current_time() noexcept
{
auto currentTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

Expand All @@ -70,7 +19,7 @@ const std::string Flakkari::Logger::get_current_time() noexcept
return std::string(buffer);
}

void Flakkari::Logger::log(int level, std::string message, std::string file, int line)
void Logger::log(int level, std::string message, std::string file, int line)
{
std::string color = COLOR_RESET;
std::string levelStr = "INFO";
Expand Down Expand Up @@ -106,7 +55,7 @@ void Flakkari::Logger::log(int level, std::string message, std::string file, int
std::cout << color << " [" << levelStr << "] " << message << " (" << file << ":" << line << ")" << COLOR_RESET << std::endl;
}

void Flakkari::Logger::log(int level, std::string message)
void Logger::log(int level, std::string message)
{
std::string color = COLOR_RESET;
std::string levelStr = "INFO";
Expand Down Expand Up @@ -142,7 +91,7 @@ void Flakkari::Logger::log(int level, std::string message)
std::cout << color << " [" << levelStr << "] " << message << COLOR_RESET << std::endl;
}

void Flakkari::Logger::log(int level, std::string message, std::string file)
void Logger::log(int level, std::string message, std::string file)
{
std::string color = COLOR_RESET;
std::string levelStr = "INFO";
Expand Down Expand Up @@ -178,7 +127,7 @@ void Flakkari::Logger::log(int level, std::string message, std::string file)
std::cout << color << " [" << levelStr << "] " << message << " (" << file << ")" << COLOR_RESET << std::endl;
}

void Flakkari::Logger::log(int level, std::string message, int line)
void Logger::log(int level, std::string message, int line)
{
std::string color = COLOR_RESET;
std::string levelStr = "INFO";
Expand Down Expand Up @@ -214,4 +163,4 @@ void Flakkari::Logger::log(int level, std::string message, int line)
std::cout << color << " [" << levelStr << "] " << message << " (" << line << ")" << COLOR_RESET << std::endl;
}

#endif /* !FLAKKARI_LOGGER_IMPLEMENTATION */
} // namespace Flakkari
59 changes: 59 additions & 0 deletions Flakkari/Logger/Logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
** EPITECH PROJECT, 2023
** Flakkari
** File description:
** Flakkari::Logger
*/

#ifndef FLAKKARI_LOGGER_HPP_
#define FLAKKARI_LOGGER_HPP_

#define LOG_INFO 0
#define LOG_LOG 1
#define LOG_DEBUG 2
#define LOG_WARNING 3
#define LOG_ERROR 4
#define LOG_FATAL 5

#include <iostream>
#include <string>
#include <chrono>
#include <ctime>

#define FLAKKARI_LOG(level, message) Flakkari::Logger::log(level, message, __FILE__, __LINE__)
#define FLAKKARI_LOG_INFO(message) FLAKKARI_LOG(LOG_INFO, message)
#define FLAKKARI_LOG_LOG(message) FLAKKARI_LOG(LOG_LOG, message)
#define FLAKKARI_LOG_DEBUG(message) FLAKKARI_LOG(LOG_DEBUG, message)
#define FLAKKARI_LOG_WARNING(message) FLAKKARI_LOG(LOG_WARNING, message)
#define FLAKKARI_LOG_ERROR(message) FLAKKARI_LOG(LOG_ERROR, message)
#define FLAKKARI_LOG_FATAL(message) FLAKKARI_LOG(LOG_FATAL, message)

#define COLOR_RESET "\033[0m"
#define COLOR_RED "\033[31m"
#define COLOR_GREEN "\033[32m"
#define COLOR_YELLOW "\033[33m"
#define COLOR_BLUE "\033[34m"
#define COLOR_MAGENTA "\033[35m"
#define COLOR_CYAN "\033[36m"
#define COLOR_WHITE "\033[37m"
#define COLOR_ORANGE "\033[38;5;208m"
#define COLOR_BRIGHT_RED "\033[91m"
#define COLOR_BRIGHT_GREEN "\033[92m"
#define COLOR_BRIGHT_YELLOW "\033[93m"
#define COLOR_BRIGHT_BLUE "\033[94m"
#define COLOR_BRIGHT_MAGENTA "\033[95m"
#define COLOR_BRIGHT_CYAN "\033[96m"
#define COLOR_BRIGHT_WHITE "\033[97m"

namespace Flakkari {
class Logger {
public:
static const std::string get_current_time() noexcept;
static void log(int level, std::string message, std::string file, int line);
static void log(int level, std::string message);
static void log(int level, std::string message, std::string file);
static void log(int level, std::string message, int line);
};
} // namespace Flakkari

#endif /* !FLAKKARI_LOGGER_HPP_ */

0 comments on commit b53fc28

Please sign in to comment.