diff --git a/.gitignore b/.gitignore index 6457baef..fec68b50 100644 --- a/.gitignore +++ b/.gitignore @@ -502,8 +502,6 @@ FodyWeavers.xsd # VS Code files for those working on multiple tools .vscode/* -!.vscode/settings.json -!.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json !.vscode/*.code-snippets @@ -569,3 +567,9 @@ _deps *.exe *.out *.app +flakkari +r-type_server + +Docs/Flakkari/ +build/ +.Test/ diff --git a/CMakeLists.txt b/CMakeLists.txt index e1af394f..2beda5fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,58 @@ # Flakkari/CMakeLists.txt cmake_minimum_required(VERSION 3.26.4) + project(R-Type_Server) -add_executable(r-type_server +# Add all your source and headers files: +set(SOURCES Flakkari/core.cpp ) -# Set the output directory for the server executable -set_target_properties(r-type_server PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +set(HEADERS + Flakkari/FlakkariLogger.hpp ) -# Custom target for cleaning server build artifacts -add_custom_target(clean-server - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/bin/r-type_server - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/_deps/r-type_server - COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/r-type_server/CMakeCache.txt - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/r-type_server/CMakeFiles -) +# Separate Build Artifacts: +set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) +set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) + +# Compiler Standards: +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Compiler Warnings: +if(MSVC) + add_compile_options(/W4) +elseif(WIN32) + add_compile_options(-Wall -Wextra -pedantic) +else() + add_compile_options(-Wall -Wextra -pedantic) +endif() + +# Create the executable +add_executable(r-type_server ${SOURCES} ${HEADERS}) + +# Include Directories: +target_include_directories(r-type_server PRIVATE ${CMAKE_SOURCE_DIR}/Flakkari) + +# Documentation: sudo apt-get install graphviz +find_package(Doxygen) +if(DOXYGEN_FOUND) + add_custom_target(doc + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile.cfg + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM) +endif() + +# Versioning: +set(PROJECT_VERSION_MAJOR 1) +set(PROJECT_VERSION_MINOR 0) +set(PROJECT_VERSION_PATCH 0) + +configure_file(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/Flakkari/config.h) + +# Install Targets: +install(TARGETS r-type_server DESTINATION bin) +install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include) diff --git a/Flakkari/CMakeLists.txt b/Flakkari/CMakeLists.txt deleted file mode 100644 index 4a58e751..00000000 --- a/Flakkari/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# src/CMakeLists.txt - -# Add all source files in the src directory -add_library(core_library core.cpp) - -# Create an executable for the source code -add_executable(my_executable core.cpp) - -# Link the executable with the core library -target_link_libraries(my_executable PRIVATE core_library) - -# Specify the output directory for the executable -set_target_properties(my_executable PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin -) diff --git a/Flakkari/FlakkariLogger.hpp b/Flakkari/FlakkariLogger.hpp new file mode 100644 index 00000000..57b640e8 --- /dev/null +++ b/Flakkari/FlakkariLogger.hpp @@ -0,0 +1,217 @@ +/* +** 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_ */ + +#ifdef FLAKKARI_LOGGER_IMPLEMENTATION + +const std::string Flakkari::Logger::get_current_time() noexcept +{ + auto currentTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + + char buffer[80]; + std::strftime(buffer, sizeof(buffer), "[ %Y-%m-%d %H:%M:%S ]", std::localtime(¤tTime)); + + return std::string(buffer); +} + +void Flakkari::Logger::log(int level, std::string message, std::string file, int line) +{ + std::string color = COLOR_RESET; + std::string levelStr = "INFO"; + + switch (level) { + case LOG_INFO: + color = COLOR_CYAN; + levelStr = "INFO"; + break; + case LOG_LOG: + color = COLOR_GREEN; + levelStr = "LOG"; + break; + case LOG_DEBUG: + color = COLOR_MAGENTA; + levelStr = "DEBUG"; + break; + case LOG_WARNING: + color = COLOR_YELLOW; + levelStr = "WARNING"; + break; + case LOG_ERROR: + color = COLOR_ORANGE; + levelStr = "ERROR"; + break; + case LOG_FATAL: + color = COLOR_BRIGHT_RED; + levelStr = "FATAL"; + break; + } + + std::cout << get_current_time(); + std::cout << color << " [" << levelStr << "] " << message << " (" << file << ":" << line << ")" << COLOR_RESET << std::endl; +} + +void Flakkari::Logger::log(int level, std::string message) +{ + std::string color = COLOR_RESET; + std::string levelStr = "INFO"; + + switch (level) { + case LOG_INFO: + color = COLOR_CYAN; + levelStr = "INFO"; + break; + case LOG_LOG: + color = COLOR_GREEN; + levelStr = "LOG"; + break; + case LOG_DEBUG: + color = COLOR_MAGENTA; + levelStr = "DEBUG"; + break; + case LOG_WARNING: + color = COLOR_YELLOW; + levelStr = "WARNING"; + break; + case LOG_ERROR: + color = COLOR_ORANGE; + levelStr = "ERROR"; + break; + case LOG_FATAL: + color = COLOR_BRIGHT_RED; + levelStr = "FATAL"; + break; + } + + std::cout << get_current_time(); + std::cout << color << " [" << levelStr << "] " << message << COLOR_RESET << std::endl; +} + +void Flakkari::Logger::log(int level, std::string message, std::string file) +{ + std::string color = COLOR_RESET; + std::string levelStr = "INFO"; + + switch (level) { + case LOG_INFO: + color = COLOR_CYAN; + levelStr = "INFO"; + break; + case LOG_LOG: + color = COLOR_GREEN; + levelStr = "LOG"; + break; + case LOG_DEBUG: + color = COLOR_MAGENTA; + levelStr = "DEBUG"; + break; + case LOG_WARNING: + color = COLOR_YELLOW; + levelStr = "WARNING"; + break; + case LOG_ERROR: + color = COLOR_ORANGE; + levelStr = "ERROR"; + break; + case LOG_FATAL: + color = COLOR_BRIGHT_RED; + levelStr = "FATAL"; + break; + } + + std::cout << get_current_time(); + std::cout << color << " [" << levelStr << "] " << message << " (" << file << ")" << COLOR_RESET << std::endl; +} + +void Flakkari::Logger::log(int level, std::string message, int line) +{ + std::string color = COLOR_RESET; + std::string levelStr = "INFO"; + + switch (level) { + case LOG_INFO: + color = COLOR_CYAN; + levelStr = "INFO"; + break; + case LOG_LOG: + color = COLOR_GREEN; + levelStr = "LOG"; + break; + case LOG_DEBUG: + color = COLOR_MAGENTA; + levelStr = "DEBUG"; + break; + case LOG_WARNING: + color = COLOR_YELLOW; + levelStr = "WARNING"; + break; + case LOG_ERROR: + color = COLOR_ORANGE; + levelStr = "ERROR"; + break; + case LOG_FATAL: + color = COLOR_BRIGHT_RED; + levelStr = "FATAL"; + break; + } + + std::cout << get_current_time(); + std::cout << color << " [" << levelStr << "] " << message << " (" << line << ")" << COLOR_RESET << std::endl; +} + +#endif /* !FLAKKARI_LOGGER_IMPLEMENTATION */ diff --git a/Flakkari/core.cpp b/Flakkari/core.cpp index 46264b32..76f26e5e 100644 --- a/Flakkari/core.cpp +++ b/Flakkari/core.cpp @@ -6,10 +6,16 @@ */ #include +#include "FlakkariMessage.hpp" using namespace std; int main() { - cout << "Server: Hello, World!" << endl; + FLAKKARI_LOG_INFO("Server: Hello, World!"); + FLAKKARI_LOG_LOG("Server: Hello, World!"); + FLAKKARI_LOG_DEBUG("Server: Hello, World!"); + FLAKKARI_LOG_WARNING("Server: Hello, World!"); + FLAKKARI_LOG_ERROR("Server: Hello, World!"); + FLAKKARI_LOG_FATAL("Server: Hello, World!"); return 0; } diff --git a/config.h.in b/config.h.in new file mode 100644 index 00000000..aae074d2 --- /dev/null +++ b/config.h.in @@ -0,0 +1,3 @@ +#define PROJECT_VERSION_MAJOR 0 +#define PROJECT_VERSION_MINOR 0 +#define PROJECT_VERSION_PATCH 1