aboutsummaryrefslogtreecommitdiff
path: root/src/Core/Log.h
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-20 02:27:02 +0200
committerhachem <im@hachem.wtf>2026-08-20 02:40:07 +0200
commit5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch)
tree34db1df17e8c7248aeeb92156d635d31c2484e3f /src/Core/Log.h
parente3abaaf59777258ba06705135a0cafcb5918ad12 (diff)
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/Core/Log.h')
-rw-r--r--src/Core/Log.h147
1 files changed, 74 insertions, 73 deletions
diff --git a/src/Core/Log.h b/src/Core/Log.h
index c7b2e47..db6b4b4 100644
--- a/src/Core/Log.h
+++ b/src/Core/Log.h
@@ -1,6 +1,6 @@
#pragma once
-#include "Core/Memory.h"
+#include "core/memory.h"
#include <string>
#include <vector>
@@ -16,140 +16,141 @@ namespace Donut
{
enum class LogLevel
{
- TRACE = 0,
- INFO = 2,
- WARN = 3,
- ERR = 4,
- FATAL = 5
+ trace = 0,
+ Info = 2,
+ Warn = 3,
+ Err = 4,
+ Fatal = 5
};
- class Logger
+ class Logger
{
public:
- static void Init();
- static void Shutdown();
+ Logger();
+ ~Logger();
+
+ static auto init() -> void;
+ static auto shutdown() -> void;
- static Ref<Logger> GetLogger();
+ static auto get_logger() -> Ref<Logger>;
template<typename... Args>
- static void Trace(const std::string_view& format, const Args&... args)
+ static auto trace(const std::string_view& format, const Args&... args) -> void
{
- auto logger = GetLogger();
- if (logger) logger->LogMessage(LogLevel::TRACE, format, args...);
+ auto logger = get_logger();
+ if (logger) logger->log_message(LogLevel::trace, format, args...);
}
template<typename... Args>
- static void Info(const std::string_view& format, const Args&... args)
+ static auto info(const std::string_view& format, const Args&... args) -> void
{
- auto logger = GetLogger();
- if (logger) logger->LogMessage(LogLevel::INFO, format, args...);
+ auto logger = get_logger();
+ if (logger) logger->log_message(LogLevel::Info, format, args...);
}
template<typename... Args>
- static void Warn(const std::string_view& format, const Args&... args)
+ static auto warn(const std::string_view& format, const Args&... args) -> void
{
- auto logger = GetLogger();
- if (logger) logger->LogMessage(LogLevel::WARN, format, args...);
+ auto logger = get_logger();
+ if (logger) logger->log_message(LogLevel::Warn, format, args...);
}
template<typename... Args>
- static void Error(const std::string_view& format, const Args&... args)
+ static auto error(const std::string_view& format, const Args&... args) -> void
{
- auto logger = GetLogger();
- if (logger) logger->LogMessage(LogLevel::ERR, format, args...);
+ auto logger = get_logger();
+ if (logger) logger->log_message(LogLevel::Err, format, args...);
}
template<typename... Args>
- static void Fatal(const std::string_view& format, const Args&... args)
+ static auto fatal(const std::string_view& format, const Args&... args) -> void
{
- auto logger = GetLogger();
- if (logger) logger->LogMessage(LogLevel::FATAL, format, args...);
+ auto logger = get_logger();
+ if (logger) logger->log_message(LogLevel::Fatal, format, args...);
}
template<typename... Args>
- void LogMessage(LogLevel level, const std::string_view& format, const Args&... args)
+ auto log_message(LogLevel level, const std::string_view& format, const Args&... args) -> void
{
- if (level < m_LogLevel)
+ if (level < m_log_level)
return;
- std::lock_guard<std::mutex> lock(m_Mutex);
- std::string message = FormatString(format, args...);
- std::string fullMessage = GetTimeStamp() + " [" + GetLogLevelString(level) + "] " + message;
-
- if (m_ConsoleOutput)
+ std::lock_guard<std::mutex> lock(m_mutex);
+ std::string message = format_string(format, args...);
+ std::string full_message = get_time_stamp() + " [" + get_log_level_string(level) + "] " + message;
+
+ if (m_console_output)
{
- SetConsoleColor(level);
- std::cout << fullMessage << std::endl;
- ResetConsoleColor();
+ set_console_color(level);
+ std::cout << full_message << std::endl;
+ reset_console_color();
}
-
- if (m_FileOutput && m_LogFile.is_open())
+
+ if (m_file_output && m_log_file.is_open())
{
- m_LogFile << fullMessage << std::endl;
- m_LogFile.flush();
+ m_log_file << full_message << std::endl;
+ m_log_file.flush();
}
}
template<typename... Args>
- std::string FormatString(const std::string_view& format, const Args&... args)
+ auto format_string(const std::string_view& format, const Args&... args) -> std::string
{
std::string result = format.data();
- std::vector<std::string> argStrings = { ToString(args)... };
-
- size_t argIndex = 0;
+ std::vector<std::string> arg_strings = { to_string(args)... };
+
+ size_t arg_index = 0;
size_t pos = 0;
-
- while ((pos = result.find("{}", pos)) != std::string::npos && argIndex < argStrings.size())
+
+ while ((pos = result.find("{}", pos)) != std::string::npos && arg_index < arg_strings.size())
{
- result.replace(pos, 2, argStrings[argIndex]);
- pos += argStrings[argIndex].length();
- argIndex++;
+ result.replace(pos, 2, arg_strings[arg_index]);
+ pos += arg_strings[arg_index].length();
+ arg_index++;
}
-
+
return result;
}
template<typename T>
- std::string ToString(const T& value)
+ auto to_string(const T& value) -> std::string
{
std::stringstream ss;
ss << value;
return ss.str();
}
- void SetLogLevel(LogLevel level) { m_LogLevel = level; }
- void EnableConsoleOutput(bool enable) { m_ConsoleOutput = enable; }
- void EnableFileOutput(bool enable) { m_FileOutput = enable; }
- void SetLogFile(const std::string& filename);
- public:
- Logger();
- ~Logger();
+ auto set_log_level(LogLevel level) -> void { m_log_level = level; }
+ auto enable_console_output(bool enable) -> void { m_console_output = enable; }
+ auto enable_file_output(bool enable) -> void { m_file_output = enable; }
+ auto set_log_file(const std::string& filename) -> void;
+
+ auto get_time_stamp() -> std::string;
+ auto get_log_level_string(LogLevel level) -> std::string;
+ auto set_console_color(LogLevel level) -> void;
+ auto reset_console_color() -> void;
- std::string GetTimeStamp();
- std::string GetLogLevelString(LogLevel level);
- void SetConsoleColor(LogLevel level);
- void ResetConsoleColor();
private:
- LogLevel m_LogLevel;
- bool m_ConsoleOutput;
- bool m_FileOutput;
- std::ofstream m_LogFile;
- std::mutex m_Mutex;
+ LogLevel m_log_level;
+ bool m_console_output;
+ bool m_file_output;
+ std::ofstream m_log_file;
+ std::mutex m_mutex;
- static Ref<Logger> s_Logger;
+ static Ref<Logger> s_logger;
};
}
#if defined(DONUT_DEBUG)
- #define DONUT_TRACE(format, ...) ::Donut::Logger::Trace(format, ##__VA_ARGS__)
- #define DONUT_INFO(format, ...) ::Donut::Logger::Info(format, ##__VA_ARGS__)
- #define DONUT_WARN(format, ...) ::Donut::Logger::Warn(format, ##__VA_ARGS__)
- #define DONUT_ERROR(format, ...) ::Donut::Logger::Error(format, ##__VA_ARGS__)
- #define DONUT_FATAL(format, ...) ::Donut::Logger::Fatal(format, ##__VA_ARGS__)
+ #define DONUT_TRACE(format, ...) ::Donut::Logger::trace(format, ##__VA_ARGS__)
+ #define DONUT_INFO(format, ...) ::Donut::Logger::info(format, ##__VA_ARGS__)
+ #define DONUT_WARN(format, ...) ::Donut::Logger::warn(format, ##__VA_ARGS__)
+ #define DONUT_ERROR(format, ...) ::Donut::Logger::error(format, ##__VA_ARGS__)
+ #define DONUT_FATAL(format, ...) ::Donut::Logger::fatal(format, ##__VA_ARGS__)
#else
#define DONUT_TRACE(format, ...) {}
#define DONUT_INFO(format, ...) {}
#define DONUT_WARN(format, ...) {}
#define DONUT_ERROR(format, ...) {}
#define DONUT_FATAL(format, ...) {}
-#endif \ No newline at end of file
+#endif