diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..359a391 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-std=c++20] diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3bec64e..b13d854 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -15,4 +15,9 @@ file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h") add_library(openblocks STATIC ${SOURCES}) set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks") target_link_libraries(openblocks ${GLEW_LIBRARIES} OpenGL::GL ReactPhysics3D::ReactPhysics3D pugixml::pugixml) -target_include_directories(openblocks PUBLIC "src" "../include") \ No newline at end of file +target_include_directories(openblocks PUBLIC "src" "../include") + +# Windows-specific dependencies +if(WIN32) + target_link_libraries(openblocks shell32.lib) +endif() \ No newline at end of file diff --git a/core/src/logger.cpp b/core/src/logger.cpp new file mode 100644 index 0000000..2d59fd3 --- /dev/null +++ b/core/src/logger.cpp @@ -0,0 +1,25 @@ +#include "logger.h" +#include "platform.h" + +#include +#include +#include + +static std::ofstream logStream; + +void Logger::init() { + initProgramLogsDir(); + + const auto now = std::chrono::system_clock::now(); + + std::string fileName = std::format("log_{0:%Y%m%d}_{0:%H%M%S}.txt", now); + + logStream = std::ofstream(getProgramLogsDir() + "/" + fileName); + Logger::debug("Logger initialized"); +} + +void Logger::finish() { + Logger::debug("Closing logger..."); + logStream.close(); +} + diff --git a/core/src/logger.h b/core/src/logger.h new file mode 100644 index 0000000..f4701f6 --- /dev/null +++ b/core/src/logger.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace Logger { + enum class LogLevel { + INFO, + DEBUG, + WARNING, + ERROR, + FATAL_ERROR, + }; + + void init(); + void finish(); + + void log(std::string message, LogLevel logLevel); + inline void info(std::string message) { log(message, LogLevel::INFO); } + inline void debug(std::string message) { log(message, LogLevel::DEBUG); } + inline void warning(std::string message) { log(message, LogLevel::WARNING); } + inline void error(std::string message) { log(message, LogLevel::ERROR); } + inline void fatalError(std::string message) { log(message, LogLevel::FATAL_ERROR); } +}; \ No newline at end of file