mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-04 09:59:03 +00:00
Improved logging capabilities
This commit is contained in:
@@ -18,13 +18,26 @@ namespace LX
|
||||
NONE
|
||||
};
|
||||
|
||||
// Different priorities in the logger //
|
||||
enum class Priority
|
||||
{
|
||||
HIGH, // Shows in all logs
|
||||
LOW // Default
|
||||
};
|
||||
|
||||
// Variadic template to allow an undefined ammount of arguments //
|
||||
template<Format format = Format::AUTO, typename... Args>
|
||||
template<Priority priority = Priority::LOW, Format format = Format::AUTO, typename... Args>
|
||||
requires AllLogable<Args...> // <- Checks all types can be outputted to the console
|
||||
|
||||
// Logs information (if the log is initalised) //
|
||||
static void out(Args... args)
|
||||
{
|
||||
// Returns if not high enough priority //
|
||||
if constexpr (priority == Priority::LOW)
|
||||
{
|
||||
RETURN_IF(s_Priority == Priority::HIGH);
|
||||
}
|
||||
|
||||
// Prints out the args ending with a new line unless specified //
|
||||
if constexpr (format == Format::AUTO) { ((*s_LogFile << ... << args) << "\n"); }
|
||||
|
||||
@@ -48,11 +61,14 @@ namespace LX
|
||||
*s_LogFile << '\n' << BREAK << '\n';
|
||||
}
|
||||
|
||||
// Initalises the log (Called by DllMain) //
|
||||
static void Init();
|
||||
// Initalises the log //
|
||||
static void Init(Priority _default);
|
||||
|
||||
private:
|
||||
// Keeps the pointer hidden to stop accidental changes //
|
||||
static std::ofstream* s_LogFile;
|
||||
|
||||
// The current priority of the log output //
|
||||
static Priority s_Priority;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace LX
|
||||
{
|
||||
// Allocates memory for the log file pointer //
|
||||
std::ofstream* Log::s_LogFile = nullptr;
|
||||
|
||||
void Log::Init()
|
||||
std::ofstream* Log::s_LogFile = nullptr;
|
||||
Log::Priority Log::s_Priority;
|
||||
|
||||
void Log::Init(Priority _default)
|
||||
{
|
||||
// The actual object holding the log file //
|
||||
// Has to be done like this to stop MSVC complaining //
|
||||
@@ -14,5 +16,8 @@ namespace LX
|
||||
// Opens the log file and assigns it to the log pointer //
|
||||
actualLog.open("log");
|
||||
s_LogFile = &actualLog;
|
||||
|
||||
// Assigns the priority //
|
||||
s_Priority = _default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user