From b53fc2802ec6ffdea54909a3b909a09afb1957ad Mon Sep 17 00:00:00 2001 From: Master_Laplace Date: Wed, 20 Dec 2023 02:06:38 +0100 Subject: [PATCH] feat(Logger): Add Logger class to Flakkari namespace --- CMakeLists.txt | 3 +- .../{FlakkariLogger.hpp => Logger/Logger.cpp} | 67 +++---------------- Flakkari/Logger/Logger.hpp | 59 ++++++++++++++++ 3 files changed, 69 insertions(+), 60 deletions(-) rename Flakkari/{FlakkariLogger.hpp => Logger/Logger.cpp} (64%) create mode 100644 Flakkari/Logger/Logger.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2beda5fb..0ea6d4ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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: diff --git a/Flakkari/FlakkariLogger.hpp b/Flakkari/Logger/Logger.cpp similarity index 64% rename from Flakkari/FlakkariLogger.hpp rename to Flakkari/Logger/Logger.cpp index 57b640e8..9ba85916 100644 --- a/Flakkari/FlakkariLogger.hpp +++ b/Flakkari/Logger/Logger.cpp @@ -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 -#include -#include -#include - -#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()); @@ -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"; @@ -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"; @@ -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"; @@ -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"; @@ -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 diff --git a/Flakkari/Logger/Logger.hpp b/Flakkari/Logger/Logger.hpp new file mode 100644 index 00000000..6e2ba4fb --- /dev/null +++ b/Flakkari/Logger/Logger.hpp @@ -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 +#include +#include +#include + +#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_ */