2021-11-05 17:34:23 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: ILogger.hpp
|
|
|
|
Date: 2021-11-1
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Aurora::Console::Logging
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
enum class ELogLevel
|
|
|
|
{
|
|
|
|
eZero = 0,
|
|
|
|
eInfo = 0,
|
|
|
|
eVerbose,
|
|
|
|
eError,
|
|
|
|
eDebug,
|
|
|
|
eWarn
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto const kLogLevelDefault = static_cast<AuUInt8>(ELogLevel::eZero);
|
|
|
|
static auto const kLogLevelUsr = static_cast<AuUInt8>(ELogLevel::eWarn);
|
|
|
|
static auto const kLogLevelMax = 16;
|
2021-11-05 17:34:23 +00:00
|
|
|
struct ILogger
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
virtual void WriteMessage(AuUInt8 level, const ConsoleMessage &msg) = 0;
|
|
|
|
|
|
|
|
virtual void PushFilter(AuUInt8 level, bool shouldFilter) = 0;
|
|
|
|
virtual void PopFilter() = 0;
|
2021-11-05 17:34:23 +00:00
|
|
|
|
|
|
|
#if defined(_AUHAS_FMT)
|
|
|
|
template<typename ... T>
|
2021-11-15 13:07:38 +00:00
|
|
|
inline void WriteLinef(AuUInt8 level, const AuString &tag, const AuString &msg, T&& ... args)
|
2021-11-05 17:34:23 +00:00
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteMessage(level, ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, std::forward<T>(args)...)));
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ... T>
|
2021-11-15 13:07:38 +00:00
|
|
|
inline void WriteLinef(AuUInt8 level, EAnsiColor color, const AuString &tag, const AuString &msg, T&& ... args)
|
2021-11-05 17:34:23 +00:00
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteMessage(level, ConsoleMessage(color, tag, fmt::format(msg, std::forward<T>(args)...)));
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
2021-11-15 13:07:38 +00:00
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
template<typename ... T>
|
|
|
|
inline void LogVerbose(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
2021-11-15 13:07:38 +00:00
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
#if defined(STAGING) || defined(DEBUG)
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogVerboseNoShip(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogVerboseNoShip(const AuString &line, T&& ... args)
|
2021-11-15 13:07:38 +00:00
|
|
|
{}
|
2021-11-05 17:34:23 +00:00
|
|
|
#endif
|
2021-11-15 13:07:38 +00:00
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
inline void DoNothing()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogInfo(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eInfo), EAnsiColor::eGreen, "Info", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogDbg(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eDebug), EAnsiColor::eYellow, "Debug", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogWarn(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eWarn), EAnsiColor::eRed, "Warn", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogError(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eError), EAnsiColor::eBoldRed, "Error", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ... T>
|
|
|
|
inline void LogGame(const AuString &line, T&& ... args)
|
|
|
|
{
|
2021-11-15 13:07:38 +00:00
|
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eBlue, "Game", line, std::forward<T>(args)...);
|
2021-11-05 17:34:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
}
|