New Logger Design & Better Logger Macros

This commit is contained in:
2026-01-17 02:38:12 +05:30
parent 71a92b8510
commit 38e4e216c8
6 changed files with 66 additions and 11 deletions

View File

@ -112,6 +112,8 @@ set(MI_OVERRIDE ON CACHE BOOL "" FORCE)
set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE) set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MI_DEBUG OFF CACHE BOOL "" FORCE)
set(MI_SHOW_ERRORS OFF CACHE BOOL "" FORCE)
set(EXPECTED_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(EXPECTED_BUILD_TESTS OFF CACHE BOOL "" FORCE)

View File

@ -23,3 +23,14 @@ if(ALREADY_PATCHED EQUAL -1)
else() else()
message(STATUS "mimalloc source is already patched. Skipping.") message(STATUS "mimalloc source is already patched. Skipping.")
endif() endif()
# Patch mimalloc complaing about false positive alignment issues in libc loader
file(READ "${SOURCE_DIR}/CMakeLists.txt" MI_CMAKE_CONTENT)
string(REPLACE
"set(mi_debug_default ON)"
"set(mi_debug_default OFF)"
MI_CMAKE_CONTENT
"${MI_CMAKE_CONTENT}"
)
file(WRITE "${SOURCE_DIR}/CMakeLists.txt" "${MI_CMAKE_CONTENT}")
message(STATUS "Patched mimalloc: Forced MI_DEBUG default to OFF to silence alignment warnings.")

View File

@ -116,10 +116,21 @@ IACore is built with CMake. You can include it in your project via `FetchContent
### CMake Example ### CMake Example
```cmake ```cmake
add_subdirectory(IACore) cmake_minimum_required(VERSION 3.28)
project(MyGame)
add_executable(MyApp Main.cpp) # Or you can use FetchContent
target_link_libraries(MyApp PRIVATE IACore) add_subdirectory(external/IACore)
# Apply IACore's standard project configuration
# This applies C++20 and strict warning flags globally to your targets.
iacore_setup_project()
# Define your targets
add_executable(MyGame src/main.cpp)
# Link IACore
target_link_libraries(MyGame PRIVATE IACore)
``` ```
## 🤝 Contributing ## 🤝 Contributing

View File

@ -16,6 +16,8 @@
#include <IACore/IACore.hpp> #include <IACore/IACore.hpp>
#include <IACore/Logger.hpp> #include <IACore/Logger.hpp>
#include <mimalloc.h>
namespace IACore namespace IACore
{ {
HighResTimePoint g_startTime{}; HighResTimePoint g_startTime{};
@ -30,6 +32,8 @@ namespace IACore
g_mainThreadID = std::this_thread::get_id(); g_mainThreadID = std::this_thread::get_id();
g_startTime = HighResClock::now(); g_startTime = HighResClock::now();
Logger::Initialize(); Logger::Initialize();
mi_option_set(mi_option_verbose, 0);
} }
VOID Terminate() VOID Terminate()

View File

@ -17,6 +17,15 @@
#include <IACore/PCH.hpp> #include <IACore/PCH.hpp>
#define IA_LOG_SET_FILE(path) IACore::Logger::EnableLoggingToDisk(path)
#define IA_LOG_SET_LEVEL(level) IACore::Logger::SetLogLevel(IACore::Logger::ELogLevel::level)
#define IA_LOG_TRACE(...) IACore::Logger::Trace(__VA_ARGS__)
#define IA_LOG_DEBUG(...) IACore::Logger::Debug(__VA_ARGS__)
#define IA_LOG_INFO(...) IACore::Logger::Info(__VA_ARGS__)
#define IA_LOG_WARN(...) IACore::Logger::Warn(__VA_ARGS__)
#define IA_LOG_ERROR(...) IACore::Logger::Error(__VA_ARGS__)
namespace IACore namespace IACore
{ {
class Logger class Logger
@ -24,7 +33,8 @@ namespace IACore
public: public:
enum class ELogLevel enum class ELogLevel
{ {
VERBOSE, TRACE,
DEBUG,
INFO, INFO,
WARN, WARN,
ERROR ERROR
@ -34,9 +44,14 @@ namespace IACore
STATIC BOOL EnableLoggingToDisk(IN PCCHAR filePath); STATIC BOOL EnableLoggingToDisk(IN PCCHAR filePath);
STATIC VOID SetLogLevel(IN ELogLevel logLevel); STATIC VOID SetLogLevel(IN ELogLevel logLevel);
template<typename... Args> STATIC VOID Status(FormatterString<Args...> fmt, Args &&...args) template<typename... Args> STATIC VOID Trace(FormatterString<Args...> fmt, Args &&...args)
{ {
LogStatus(std::vformat(fmt.get(), std::make_format_args(args...))); LogTrace(std::vformat(fmt.get(), std::make_format_args(args...)));
}
template<typename... Args> STATIC VOID Debug(FormatterString<Args...> fmt, Args &&...args)
{
LogDebug(std::vformat(fmt.get(), std::make_format_args(args...)));
} }
template<typename... Args> STATIC VOID Info(FormatterString<Args...> fmt, Args &&...args) template<typename... Args> STATIC VOID Info(FormatterString<Args...> fmt, Args &&...args)
@ -58,7 +73,12 @@ namespace IACore
private: private:
#if IA_DISABLE_LOGGING > 0 #if IA_DISABLE_LOGGING > 0
STATIC VOID LogStatus(IN String &&msg) STATIC VOID LogTrace(IN String &&msg)
{
UNUSED(msg);
}
STATIC VOID LogDebug(IN String &&msg)
{ {
UNUSED(msg); UNUSED(msg);
} }
@ -78,10 +98,16 @@ namespace IACore
UNUSED(msg); UNUSED(msg);
} }
#else #else
STATIC VOID LogStatus(IN String &&msg) STATIC VOID LogTrace(IN String &&msg)
{ {
if (s_logLevel <= ELogLevel::VERBOSE) if (s_logLevel <= ELogLevel::TRACE)
LogInternal(__CC_WHITE, "STATUS", IA_MOVE(msg)); LogInternal(__CC_WHITE, "TRACE", IA_MOVE(msg));
}
STATIC VOID LogDebug(IN String &&msg)
{
if (s_logLevel <= ELogLevel::DEBUG)
LogInternal(__CC_CYAN, "DEBUG", IA_MOVE(msg));
} }
STATIC VOID LogInfo(IN String &&msg) STATIC VOID LogInfo(IN String &&msg)

View File

@ -119,6 +119,7 @@
# include <cstddef> # include <cstddef>
# include <chrono> # include <chrono>
# include <iomanip> # include <iomanip>
# include <charconv>
# include <fstream> # include <fstream>
# include <iostream> # include <iostream>
# include <concepts> # include <concepts>