113 lines
3.8 KiB
C++
113 lines
3.8 KiB
C++
/***
|
|
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::Logging
|
|
{
|
|
using ConsoleMessage = Console::ConsoleMessage;
|
|
using EAnsiColor = Console::EAnsiColor;
|
|
|
|
AUE_DEFINE(ELogLevel,
|
|
(
|
|
eInfo,
|
|
eVerbose,
|
|
eError,
|
|
eDebug,
|
|
eWarn,
|
|
eCritical
|
|
));
|
|
|
|
static auto const kLogLevelDefault = static_cast<AuUInt8>(kELogLevelMinLegal);
|
|
static auto const kLogLevelUsr = static_cast<AuUInt8>(kELogLevelMaxLegal);
|
|
static auto const kLogLevelMax = AuUInt8(255);
|
|
|
|
struct ILogger
|
|
{
|
|
virtual void WriteMessage(AuUInt8 level, const ConsoleMessage &msg) = 0;
|
|
|
|
virtual void PushFilter(AuUInt8 level, bool shouldFilter) = 0;
|
|
virtual void PopFilter() = 0;
|
|
|
|
virtual bool ExchangeMitigationState(bool bMitigationsEnabled) = 0;
|
|
|
|
#if defined(_AUHAS_FMT)
|
|
template<typename ... T>
|
|
inline void WriteLinef(AuUInt8 level, const AuString &tag, fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteMessage(level, ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, AuForward<T>(args)...)));
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void WriteLinef(AuUInt8 level, EAnsiColor color, const AuString &tag, fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteMessage(level, ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogVerbose(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", msg, AuForward<T>(args)...);
|
|
}
|
|
|
|
#if defined(STAGING) || defined(DEBUG)
|
|
template<typename ... T>
|
|
inline void LogVerboseNoShip(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", msg, AuForward<T>(args)...);
|
|
}
|
|
#else
|
|
template<typename ... T>
|
|
inline void LogVerboseNoShip(fmt::format_string<T...> msg, T&& ... args)
|
|
{}
|
|
#endif
|
|
|
|
inline void DoNothing()
|
|
{
|
|
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogInfo(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eInfo), EAnsiColor::eGreen, "Info", msg, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogDbg(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eDebug), EAnsiColor::eYellow, "Debug", msg, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogWarn(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eWarn), EAnsiColor::eRed, "Warn", msg, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogCritical(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eCritical), EAnsiColor::eBoldRed, "Critical", msg, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogError(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eError), EAnsiColor::eBoldRed, "Error", msg, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogGame(fmt::format_string<T...> msg, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eBlue, "Game", msg, AuForward<T>(args)...);
|
|
}
|
|
#endif
|
|
|
|
AURT_ADD_USR_DATA;
|
|
};
|
|
} |