113 lines
3.7 KiB
C++
113 lines
3.7 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, const AuString &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, const AuString &msg, T&& ... args)
|
|
{
|
|
WriteMessage(level, ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogVerbose(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
|
|
}
|
|
|
|
#if defined(STAGING) || defined(DEBUG)
|
|
template<typename ... T>
|
|
inline void LogVerboseNoShip(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
|
|
}
|
|
#else
|
|
template<typename ... T>
|
|
inline void LogVerboseNoShip(const AuString &line, T&& ... args)
|
|
{}
|
|
#endif
|
|
|
|
inline void DoNothing()
|
|
{
|
|
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogInfo(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eInfo), EAnsiColor::eGreen, "Info", line, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogDbg(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eDebug), EAnsiColor::eYellow, "Debug", line, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogWarn(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eWarn), EAnsiColor::eRed, "Warn", line, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogCritical(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eCritical), EAnsiColor::eBoldRed, "Critical", line, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogError(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eError), EAnsiColor::eBoldRed, "Error", line, AuForward<T>(args)...);
|
|
}
|
|
|
|
template<typename ... T>
|
|
inline void LogGame(const AuString &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eBlue, "Game", line, AuForward<T>(args)...);
|
|
}
|
|
#endif
|
|
|
|
AURT_ADD_USR_DATA;
|
|
};
|
|
} |