Jamie Reece Wilson
541f12acfb
[+] AuLogInfoOnce [+] AuLogDbgOnce [+] AuLogErrorOnce [+] AuLogVerboseOnce
266 lines
9.3 KiB
C++
266 lines
9.3 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 "IFormatter.hpp"
|
|
#include "IFormatterContainer.hpp"
|
|
#include "ILogger.hpp"
|
|
#include "IBasicSink.hpp"
|
|
#include "IFormattedSink.hpp"
|
|
#include "IBasicSinkRB.hpp"
|
|
#include "IIPCLogger.hpp"
|
|
#include "Sinks.hpp"
|
|
#include "LogClasses.hpp"
|
|
|
|
#include <Aurora/Debug/MemoryCrunch.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)
|
|
{
|
|
AU_DEBUG_MEMCRUNCH;
|
|
|
|
try
|
|
{
|
|
WriteLine(level, ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, AuForward<T>(args)...)));
|
|
}
|
|
catch (...)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
template<typename Line_t, typename ... T>
|
|
inline void WriteLinef(AuUInt8 level, EAnsiColor color, const AuString &tag, const Line_t &msg, T&& ... args)
|
|
{
|
|
AU_DEBUG_MEMCRUNCH;
|
|
|
|
try
|
|
{
|
|
WriteLine(level, ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
|
|
}
|
|
catch (...)
|
|
{;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
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 LogCritical(const Line_t &line, T&& ... args)
|
|
{
|
|
WriteLinef(static_cast<AuUInt8>(ELogLevel::eCritical), EAnsiColor::eBoldRed, "Critical", 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, typename ... T>
|
|
inline void LogCritical(const Line_t &line, T&& ... args)
|
|
{
|
|
WriteLine(static_cast<AuUInt8>(ELogLevel::eCritical), ConsoleMessage(EAnsiColor::eBoldRed, "Critical", 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)
|
|
ADD_AU_GLOBAL_ALIAS(Critical)
|
|
|
|
#define AuLogWarnOnce(...) \
|
|
{ \
|
|
static __audetail::InitOnceABI gInitOnce; \
|
|
if (Aurora::Threading::InitOnceLocker::TryLock(&gInitOnce)) \
|
|
{ \
|
|
AuLogWarn(__VA_ARGS__); \
|
|
Aurora::Threading::InitOnceLocker::Finish(&gInitOnce); \
|
|
} \
|
|
}
|
|
|
|
#define AuLogInfoOnce(...) \
|
|
{ \
|
|
static __audetail::InitOnceABI gInitOnce; \
|
|
if (Aurora::Threading::InitOnceLocker::TryLock(&gInitOnce)) \
|
|
{ \
|
|
AuLogInfo(__VA_ARGS__); \
|
|
Aurora::Threading::InitOnceLocker::Finish(&gInitOnce); \
|
|
} \
|
|
}
|
|
|
|
#define AuLogDbgOnce(...) \
|
|
{ \
|
|
static __audetail::InitOnceABI gInitOnce; \
|
|
if (Aurora::Threading::InitOnceLocker::TryLock(&gInitOnce)) \
|
|
{ \
|
|
AuLogDbg(__VA_ARGS__); \
|
|
Aurora::Threading::InitOnceLocker::Finish(&gInitOnce); \
|
|
} \
|
|
}
|
|
|
|
#define AuLogErrorOnce(...) \
|
|
{ \
|
|
static __audetail::InitOnceABI gInitOnce; \
|
|
if (Aurora::Threading::InitOnceLocker::TryLock(&gInitOnce)) \
|
|
{ \
|
|
AuLogError(__VA_ARGS__); \
|
|
Aurora::Threading::InitOnceLocker::Finish(&gInitOnce); \
|
|
} \
|
|
}
|
|
|
|
#define AuLogVerboseOnce(...) \
|
|
{ \
|
|
static __audetail::InitOnceABI gInitOnce; \
|
|
if (Aurora::Threading::InitOnceLocker::TryLock(&gInitOnce)) \
|
|
{ \
|
|
AuLogVerbose(__VA_ARGS__); \
|
|
Aurora::Threading::InitOnceLocker::Finish(&gInitOnce); \
|
|
} \
|
|
}
|
|
|
|
#define AuLogCriticalOnce(...) \
|
|
{ \
|
|
static __audetail::InitOnceABI gInitOnce; \
|
|
if (Aurora::Threading::InitOnceLocker::TryLock(&gInitOnce)) \
|
|
{ \
|
|
AuLogCritical(__VA_ARGS__); \
|
|
Aurora::Threading::InitOnceLocker::Finish(&gInitOnce); \
|
|
} \
|
|
}
|
|
|
|
#if defined(STAGING) || defined(DEBUG)
|
|
ADD_AU_GLOBAL_ALIAS(VerboseNoShip)
|
|
#else
|
|
#define AuLogVerboseNoShip(...)
|
|
#endif
|
|
|
|
#undef ADD_AU_GLOBAL_ALIAS |