AuroraRuntime/Include/Aurora/Logging/Logging.hpp
Reece c1976d771b [*] Compiler warning
[*] Disambiguate auContainerUtils
[*] Optimize AuLogXXX / remove alloc
[*] Didn't commit two auROXTL idiom updates (ExceptionWatcher and Logging)
2022-03-30 19:07:15 +01:00

168 lines
5.0 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Logging.hpp
Date: 2021-9-21
Author: Reece
***/
#pragma once
#include "ILogger.hpp"
#include "IBasicSink.hpp"
#include "IBasicSinkRB.hpp"
#include "Sinks.hpp"
namespace Aurora::Logging
{
/// Writes a log message to the console subscribers and telemetry sinks
AUKN_SYM void WriteLine(AuUInt8 level, const Console::ConsoleMessage &msg);
/**
* @brief Overloads the ILogger backend of the AuLogXX functions
* @param defaultGlobalLogger
* @return
*/
AUKN_SYM void SetGlobalLogger(const AuSPtr<Logging::ILogger> &defaultGlobalLogger);
#if defined(_AUHAS_FMT)
template<typename Line_t, typename ... T>
inline void WriteLinef(AuUInt8 level, const AuString &tag, const Line_t &msg, T&& ... args)
{
WriteLine(level, ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, AuForward<T>(args)...)));
}
template<typename Line_t, typename ... T>
inline void WriteLinef(AuUInt8 level, EAnsiColor color, const AuString &tag, const Line_t &msg, T&& ... args)
{
WriteLine(level, ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
}
template<typename Line_t, typename ... T>
inline void LogVerbose(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
}
#if defined(STAGING) || defined(DEBUG)
template<typename Line_t, typename ... T>
inline auline void LogVerboseNoShip(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
}
#else
template<typename Line_t, typename ... T>
inline auline void LogVerboseNoShip(const Line_t &line, T&& ... args)
{}
#endif
inline void DoNothing()
{
}
template<typename Line_t, typename ... T>
inline void LogInfo(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eInfo), EAnsiColor::eGreen, "Info", line, AuForward<T>(args)...);
}
template<typename Line_t, typename ... T>
inline void LogDbg(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eDebug), EAnsiColor::eYellow, "Debug", line, AuForward<T>(args)...);
}
template<typename Line_t, typename ... T>
inline void LogWarn(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eWarn), EAnsiColor::eRed, "Warn", line, AuForward<T>(args)...);
}
template<typename Line_t, typename ... T>
inline void LogError(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eError), EAnsiColor::eBoldRed, "Error", line, AuForward<T>(args)...);
}
template<typename Line_t, typename ... T>
inline void LogGame(const Line_t &line, T&& ... args)
{
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eBlue, "Game", line, AuForward<T>(args)...);
}
#else
static void LogVerbose(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eVerbose), ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
}
#if defined(STAGING) || defined(DEBUG)
static void LogVerboseNoShip(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eVerbose), ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
}
#else
#define LogVerboseNoShip(...) DoNothing()
#endif
static void DoNothing()
{
}
template<typename Line_t>
static void LogInfo(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eInfo), ConsoleMessage(EAnsiColor::eGreen, "Info", line));
}
template<typename Line_t>
static void LogDbg(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eDebug), ConsoleMessage(EAnsiColor::eYellow, "Debug", line));
}
template<typename Line_t>
static void LogWarn(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eWarn), ConsoleMessage(EAnsiColor::eRed, "Warn", line));
}
template<typename Line_t>
static void LogError(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eError), ConsoleMessage(EAnsiColor::eBoldRed, "Error", line));
}
template<typename Line_t>
static void LogGame(const Line_t &line)
{
WriteLine(static_cast<AuUInt8>(ELogLevel::eGame), ConsoleMessage(EAnsiColor::eBlue, "Game", line));
}
#endif
}
#define ADD_AU_GLOBAL_ALIAS(level)\
template<typename ... T> \
static void AuLog ## level(T&& ... args) \
{ \
Aurora::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
#undef ADD_AU_GLOBAL_ALIAS