AuroraRuntime/Include/Aurora/Console/Logging/Logging.hpp

151 lines
4.4 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Logging.hpp
Date: 2021-9-21
2021-06-27 21:25:29 +00:00
Author: Reece
***/
#pragma once
#include "ILogger.hpp"
#include "IBasicSink.hpp"
#include "IBasicSinkRB.hpp"
#include "Sinks.hpp"
2021-06-27 21:25:29 +00:00
namespace Aurora::Console::Logging
{
2021-09-06 10:58:08 +00:00
#if defined(_AUHAS_FMT)
2022-01-21 22:37:29 +00:00
2021-06-27 21:25:29 +00:00
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void WriteLinef(AuUInt8 level, const AuString &tag, const AuString &msg, T&& ... args)
2021-06-27 21:25:29 +00:00
{
2022-01-21 22:37:29 +00:00
WriteLine(level, ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, AuForward<T>(args)...)));
2021-06-27 21:25:29 +00:00
}
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void WriteLinef(AuUInt8 level, EAnsiColor color, const AuString &tag, const AuString &msg, T&& ... args)
2021-06-27 21:25:29 +00:00
{
2022-01-21 22:37:29 +00:00
WriteLine(level, ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
2021-06-27 21:25:29 +00:00
}
2022-01-21 22:37:29 +00:00
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void LogVerbose(const AuString &line, T&& ... args)
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
}
2022-01-21 22:37:29 +00:00
#if defined(STAGING) || defined(DEBUG)
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline auline void LogVerboseNoShip(const AuString &line, T&& ... args)
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
}
#else
2022-01-21 22:37:29 +00:00
template<typename ... T>
inline auline void LogVerboseNoShip(const AuString &line, T&& ... args)
{}
#endif
2021-06-27 21:25:29 +00:00
2022-01-21 22:37:29 +00:00
inline void DoNothing()
{
}
2021-06-27 21:25:29 +00:00
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void LogInfo(const AuString &line, T&& ... args)
2021-06-27 21:25:29 +00:00
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eInfo), EAnsiColor::eGreen, "Info", line, AuForward<T>(args)...);
2021-06-27 21:25:29 +00:00
}
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void LogDbg(const AuString &line, T&& ... args)
2021-06-27 21:25:29 +00:00
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eDebug), EAnsiColor::eYellow, "Debug", line, AuForward<T>(args)...);
2021-06-27 21:25:29 +00:00
}
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void LogWarn(const AuString &line, T&& ... args)
2021-06-27 21:25:29 +00:00
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eWarn), EAnsiColor::eRed, "Warn", line, AuForward<T>(args)...);
2021-06-27 21:25:29 +00:00
}
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void LogError(const AuString &line, T&& ... args)
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eError), EAnsiColor::eBoldRed, "Error", line, AuForward<T>(args)...);
}
2021-06-27 21:25:29 +00:00
template<typename ... T>
2022-01-21 22:37:29 +00:00
inline void LogGame(const AuString &line, T&& ... args)
2021-06-27 21:25:29 +00:00
{
2022-01-21 22:37:29 +00:00
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eBlue, "Game", line, AuForward<T>(args)...);
2021-06-27 21:25:29 +00:00
}
#else
static void LogVerbose(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eVerbose), ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
}
#if defined(STAGING) || defined(DEBUG)
static void LogVerboseNoShip(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eVerbose), ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
}
#else
#define LogVerboseNoShip(...) DoNothing()
#endif
static void DoNothing()
{
}
static void LogInfo(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eInfo), ConsoleMessage(EAnsiColor::eGreen, "Info", line));
}
static void LogDbg(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eDebug), ConsoleMessage(EAnsiColor::eYellow, "Debug", line));
}
static void LogWarn(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eWarn), ConsoleMessage(EAnsiColor::eRed, "Warn", line));
}
static void LogError(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eError), ConsoleMessage(EAnsiColor::eBoldRed, "Error", line));
}
static void LogGame(const AuString &line)
{
2022-01-21 22:37:29 +00:00
WriteLine(static_cast<AuUInt8>(ELogLevel::eGame), ConsoleMessage(EAnsiColor::eBlue, "Game", line));
}
2021-09-06 10:58:08 +00:00
#endif
}
#define ADD_AU_GLOBAL_ALIAS(level)\
template<typename ... T> \
static void AuLog ## level(T&& ... args) \
{ \
Aurora::Console::Logging::Log ## level(AuForward<T>(args)...); \
}
ADD_AU_GLOBAL_ALIAS(Info)
ADD_AU_GLOBAL_ALIAS(Dbg)
ADD_AU_GLOBAL_ALIAS(Warn)
ADD_AU_GLOBAL_ALIAS(Error)
ADD_AU_GLOBAL_ALIAS(Game)
ADD_AU_GLOBAL_ALIAS(Verbose)
#if defined(STAGING) || defined(DEBUG)
ADD_AU_GLOBAL_ALIAS(VerboseNoShip)
#else
#define AuLogVerboseNoShip(...)
#endif