diff --git a/src/Utils/Utils/Logging/Log.cpp b/src/Utils/Utils/Logging/Log.cpp new file mode 100644 index 00000000..eee3d6d3 --- /dev/null +++ b/src/Utils/Utils/Logging/Log.cpp @@ -0,0 +1,42 @@ +#include "Log.h" + +#include +#include + +namespace con +{ + LogLevel globalLogLevel = LogLevel::INFO; + bool globalUseColor = true; + + void _debug_internal(const std::string& str) + { + if (globalUseColor) + std::cout << std::format("\x1B[90m{}\x1B[0m\n", str); + else + std::cout << std::format("{}\n", str); + } + + void _info_internal(const std::string& str) + { + if (globalUseColor) + std::cout << std::format("\x1B[37m{}\x1B[0m\n", str); + else + std::cout << std::format("{}\n", str); + } + + void _warn_internal(const std::string& str) + { + if (globalUseColor) + std::cout << std::format("\x1B[33m{}\x1B[0m\n", str); + else + std::cout << std::format("{}\n", str); + } + + void _error_internal(const std::string& str) + { + if (globalUseColor) + std::cerr << std::format("\x1B[31m{}\x1B[0m\n", str); + else + std::cerr << std::format("{}\n", str); + } +} // namespace con diff --git a/src/Utils/Utils/Logging/Log.h b/src/Utils/Utils/Logging/Log.h new file mode 100644 index 00000000..1e72af34 --- /dev/null +++ b/src/Utils/Utils/Logging/Log.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +namespace con +{ + enum class LogLevel + { + DEBUG = 0, + INFO, + WARN, + ERROR + }; + + extern LogLevel globalLogLevel; + extern bool globalUseColor; + + void _debug_internal(const std::string& str); + void _info_internal(const std::string& str); + void _warn_internal(const std::string& str); + void _error_internal(const std::string& str); + + template void debug(std::format_string fmt, Args&&... args) + { + if (static_cast(globalLogLevel) > static_cast(LogLevel::DEBUG)) + return; + _debug_internal(std::vformat(fmt.get(), std::make_format_args(args...))); + } + + template void info(std::format_string fmt, Args&&... args) + { + if (static_cast(globalLogLevel) > static_cast(LogLevel::INFO)) + return; + _info_internal(std::vformat(fmt.get(), std::make_format_args(args...))); + } + + template void warn(std::format_string fmt, Args&&... args) + { + if (static_cast(globalLogLevel) > static_cast(LogLevel::WARN)) + return; + _warn_internal(std::vformat(fmt.get(), std::make_format_args(args...))); + } + + template void error(std::format_string fmt, Args&&... args) + { + _error_internal(std::vformat(fmt.get(), std::make_format_args(args...))); + } +} // namespace con