[*] preparing for autismo

This commit is contained in:
Reece Wilson 2022-01-21 22:37:29 +00:00
parent 66870a0f1a
commit 8db441ff33
13 changed files with 194 additions and 55 deletions

View File

@ -12,8 +12,14 @@
namespace Aurora::Console
{
namespace Logging
{
struct ILogger;
}
/// Writes a log message to the console subscribers and telemetry outputs
AUKN_SYM void WriteLine(const ConsoleMessage &msg);
AUKN_SYM void WriteLine(AuUInt8 level, const ConsoleMessage &msg);
AUKN_SYM void SetGlobalLogger(const AuSPtr<Logging::ILogger> &defaultGlobalLogger);
/// Consider using the following function for asynchronous utf-8 processed line based input -
/// Hooks::SetCallbackAndDisableCmdProcessing(...)

View File

@ -15,80 +15,83 @@
namespace Aurora::Console::Logging
{
#if defined(_AUHAS_FMT)
template<typename ... T>
static void WriteLinef(const AuString &tag, const AuString &msg, T&& ... args)
inline void WriteLinef(AuUInt8 level, const AuString &tag, const AuString &msg, T&& ... args)
{
WriteLine(ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, AuForward<T>(args)...)));
WriteLine(level, ConsoleMessage(EAnsiColor::eReset, tag, fmt::format(msg, AuForward<T>(args)...)));
}
template<typename ... T>
static void WriteLinef(EAnsiColor color, const AuString &tag, const AuString &msg, T&& ... args)
inline void WriteLinef(AuUInt8 level, EAnsiColor color, const AuString &tag, const AuString &msg, T&& ... args)
{
WriteLine(ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
WriteLine(level, ConsoleMessage(color, tag, fmt::format(msg, AuForward<T>(args)...)));
}
template<typename ... T>
static void LogVerbose(const AuString &line, T&& ... args)
inline void LogVerbose(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
}
#if defined(STAGING) || defined(DEBUG)
template<typename ... T>
static void LogVerboseNoShip(const AuString &line, T&& ... args)
inline auline void LogVerboseNoShip(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eYellow, "Verbose", line, AuForward<T>(args)...);
}
#else
#define LogVerboseNoShip(...) DoNothing()
template<typename ... T>
inline auline void LogVerboseNoShip(const AuString &line, T&& ... args)
{}
#endif
static void DoNothing()
inline void DoNothing()
{
}
template<typename ... T>
static void LogInfo(const AuString &line, T&& ... args)
inline void LogInfo(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eGreen, "Info", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eInfo), EAnsiColor::eGreen, "Info", line, AuForward<T>(args)...);
}
template<typename ... T>
static void LogDbg(const AuString &line, T&& ... args)
inline void LogDbg(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eYellow, "Debug", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eDebug), EAnsiColor::eYellow, "Debug", line, AuForward<T>(args)...);
}
template<typename ... T>
static void LogWarn(const AuString &line, T&& ... args)
inline void LogWarn(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eRed, "Warn", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eWarn), EAnsiColor::eRed, "Warn", line, AuForward<T>(args)...);
}
template<typename ... T>
static void LogError(const AuString &line, T&& ... args)
inline void LogError(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eBoldRed, "Error", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eError), EAnsiColor::eBoldRed, "Error", line, AuForward<T>(args)...);
}
template<typename ... T>
static void LogGame(const AuString &line, T&& ... args)
inline void LogGame(const AuString &line, T&& ... args)
{
WriteLinef(EAnsiColor::eBlue, "Game", line, AuForward<T>(args)...);
WriteLinef(static_cast<AuUInt8>(ELogLevel::eVerbose), EAnsiColor::eBlue, "Game", line, AuForward<T>(args)...);
}
#else
static void LogVerbose(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eVerbose), ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
}
#if defined(STAGING) || defined(DEBUG)
static void LogVerboseNoShip(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eVerbose), ConsoleMessage(EAnsiColor::eYellow, "Verbose", line));
}
#else
#define LogVerboseNoShip(...) DoNothing()
@ -101,27 +104,27 @@ namespace Aurora::Console::Logging
static void LogInfo(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eGreen, "Info", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eInfo), ConsoleMessage(EAnsiColor::eGreen, "Info", line));
}
static void LogDbg(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eYellow, "Debug", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eDebug), ConsoleMessage(EAnsiColor::eYellow, "Debug", line));
}
static void LogWarn(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eRed, "Warn", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eWarn), ConsoleMessage(EAnsiColor::eRed, "Warn", line));
}
static void LogError(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eBoldRed, "Error", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eError), ConsoleMessage(EAnsiColor::eBoldRed, "Error", line));
}
static void LogGame(const AuString &line)
{
WriteLine(ConsoleMessage(EAnsiColor::eBlue, "Game", line));
WriteLine(static_cast<AuUInt8>(ELogLevel::eGame), ConsoleMessage(EAnsiColor::eBlue, "Game", line));
}
#endif

View File

@ -22,6 +22,7 @@
}
Aurora::Console::Logging::WriteLinef(
static_cast<AuUInt8>(Aurora::Console::Logging::ELogLevel::eError),
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression address: {} {}:{}", func, file, fileno);
@ -107,11 +108,13 @@
}
Aurora::Console::Logging::WriteLinef(
static_cast<AuUInt8>(Aurora::Console::Logging::ELogLevel::eError),
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression address: {} {}:{}", func, file, fileno);
Aurora::Console::Logging::WriteLinef(
static_cast<AuUInt8>(Aurora::Console::Logging::ELogLevel::eError),
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression failed: {}", exp);
@ -156,6 +159,7 @@
}
Aurora::Console::Logging::WriteLinef(
static_cast<AuUInt8>(Aurora::Console::Logging::ELogLevel::eError),
Aurora::Console::EAnsiColor::eBoldRed,
"Fatal",
"Expression failed: {}", exp);

View File

@ -11,7 +11,7 @@
template<typename ... T>
static inline void __declspec(noreturn) SysPanic(T... args)
{
Aurora::Console::Logging::WriteLinef(Aurora::Console::EAnsiColor::eBoldRed, "Fatal", AuForward<T>(args)...);
Aurora::Console::Logging::WriteLinef(static_cast<AuUInt8>(Aurora::Console::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", AuForward<T>(args)...);
Aurora::Debug::Panic();
}
#endif

View File

@ -27,11 +27,11 @@ namespace Aurora::Time
{
if (AuExchange(finished_, true)) return;
auto time = timer_.End();
Aurora::Console::Logging::LogDbg("[Benchmark] {} took {}", message_, ConvertMSToTimescaleEN(time));
Aurora::Console::Logging::LogDbg("[Benchmark] {} took {}", message_, ConvertNSToTimescale(time));
}
private:
Timer timer_;
TimerHighRes timer_;
bool finished_ {};
AuString message_;
};

View File

@ -9,7 +9,59 @@
namespace Aurora::Time
{
static inline AuString ConvertMSToTimescaleEN(AuUInt32 ms)
static auline AuString TimeLocaleGetDayChar()
{
return "d"; //for.now
}
static auline AuString TimeLocaleS()
{
return "s";
}
static auline AuString TimeLocaleGetMSChar()
{
return "ms"; //for.now
}
static AuString &_TextPrepadZeroIfOne(AuString &in)
{
if (in.size() == 1) in.insert(in.begin(), '0');
return in;
}
static AuString _TextPrepadZeroIfOne(const AuString &in)
{
AuString ret = in;
if (ret.size() == 1) ret.insert(ret.begin(), '0');
return ret;
}
static AuString _TextPrepadZeroMS(const AuString &in)
{
AuString ret = in;
if (ret.size() == 1) ret.insert(0, "000", 3);
if (ret.size() == 2) ret.insert(0, "000", 2);
if (ret.size() == 3) ret.insert(0, "000", 1);
while (ret.size() > 1 && ret[ret.size() - 1] == '0')
ret.pop_back();
return ret;
}
static AuString _TextPrepadZeroNS(const AuString &in)
{
AuString ret = in;
if (ret.size() == 1) ret.insert(0, "000000", 6);
if (ret.size() == 2) ret.insert(0, "000000", 5);
if (ret.size() == 3) ret.insert(0, "000000", 4);
if (ret.size() == 4) ret.insert(0, "000000", 3);
if (ret.size() == 5) ret.insert(0, "000000", 2);
if (ret.size() == 6) ret.insert(0, "000000", 1);
while (ret.size() > 1 && ret[ret.size() - 1] == '0')
ret.pop_back();
return ret;
}
static auline AuString ConvertMSToTimescale(AuUInt32 ms)
{
const auto msDiv1000 = ms / 1000; // seconds
const auto msDiv1000Mod60 = msDiv1000 % 60; // remaining seconds relative to next whole minute
@ -17,26 +69,27 @@ namespace Aurora::Time
if (ms < 1000)
{
return AuToString(ms) + "ms";
return AuToString(ms) + TimeLocaleGetMSChar();
}
else if (ms < (1000 * 60))
{
auto s = msDiv1000;
auto remMs = ms % 1000;
return AuToString(s) + "." + AuToString(remMs) + "s";
return _TextPrepadZeroIfOne(AuToString(s)) + "." + _TextPrepadZeroMS(AuToString(remMs)) + TimeLocaleS();
}
else if (ms < (1000 * 60 * 60))
{
auto m = msDiv1000Div60;
auto remS = msDiv1000Mod60;
return AuToString(m) + "m " + AuToString(remS) + "s";
return _TextPrepadZeroIfOne(AuToString(m)) + ":" + _TextPrepadZeroIfOne(AuToString(remS));
}
else if (ms < (1000 * 60 * 60 * 24))
{
auto h = msDiv1000Div60 / 60;
auto remM = msDiv1000Div60;
auto remS = msDiv1000Mod60;
return AuToString(h) + "h " + AuToString(remM) + "m " + AuToString(remS) + "s";
return _TextPrepadZeroIfOne(AuToString(h)) + ":" + _TextPrepadZeroIfOne(AuToString(remM)) + ":" + _TextPrepadZeroIfOne(AuToString(remS));
}
else
{
@ -44,9 +97,24 @@ namespace Aurora::Time
auto h = (msDiv1000Div60 / 60) - (d * 24);
auto remM = msDiv1000Div60;
auto remS = msDiv1000Mod60;
return AuToString(d) + "d " + AuToString(h) + "h " + AuToString(remM) + "m " + AuToString(remS) + "s";
return AuToString(d) + TimeLocaleGetDayChar() + " " + _TextPrepadZeroIfOne(AuToString(h)) + ":" + _TextPrepadZeroIfOne(AuToString(remM)) + ":" + _TextPrepadZeroIfOne(AuToString(remS));
}
}
static auline AuString ConvertNSToTimescale(AuUInt64 ns)
{
if (ns < AuUInt64(1000000000))
{
const auto ms = ns / 1000000;
const auto remNs = ns % 1000000;
return _TextPrepadZeroMS(AuToString(ms)) + "." + _TextPrepadZeroNS(AuToString(remNs)) + TimeLocaleGetMSChar();
}
else
{
return ConvertMSToTimescale(ns / AuUInt64(1000000000));
}
}
}
#include "Clock.hpp"

View File

@ -16,11 +16,47 @@
namespace Aurora::Console
{
AUKN_SYM void WriteLine(const ConsoleMessage &msg)
static AuList<AuSPtr<IBasicSink>> gDefaultSinks;
static AuSPtr<ILogger> gDefaultLogger;
static AuSPtr<ILogger> gUserLogger;
static AuSPtr<ILogger> CreateDefaultLogger()
{
return {};
}
AUKN_SYM void WriteLine(AuUInt8 level, const ConsoleMessage &msg)
{
Hooks::WriteLine(msg);
if (gUserLogger)
{
gUserLogger->WriteMessage(level, msg);
}
else if (!gDefaultLogger)
{
auto tmp = CreateDefaultLogger();
if (tmp)
{
tmp->WriteMessage(level, msg);
}
}
else
{
gDefaultLogger->WriteMessage(level, msg);
}
}
void AddDefaultLogger(const AuSPtr<IBasicSink> &logger)
{
gDefaultSinks.push_back(logger);
}
static void FinailizeDefaultLogger()
{
gDefaultLogger = CreateDefaultLogger();
//gDefaultSinks.clear();
}
AUKN_SYM AuUInt32 ReadStdIn(void *buffer, AuUInt32 length)
{
return ConsoleStd::ReadStdIn(buffer, length);
@ -53,6 +89,7 @@ namespace Aurora::Console
{
ConsoleFIO::Init();
InitFlusher();
FinailizeDefaultLogger();
}
void Pump()
@ -75,6 +112,7 @@ namespace Aurora::Console
AUKN_SYM void OpenLateStd()
{
ConsoleStd::Start();
FinailizeDefaultLogger();
}
AUKN_SYM void OpenLateGUI()

View File

@ -9,6 +9,9 @@
namespace Aurora::Console
{
void AddDefaultLogger(const AuSPtr<IBasicSink> &logger);
void Init();
void Init2();
void Pump();

View File

@ -18,10 +18,12 @@ namespace Aurora::Crypto::PEM
int fail = 0;
bool finished = 0;
str.reserve(src.size());
try
{
str.reserve(src.size());
Parse::SplitNewlines(src,
[&](const AuString &src)
Parse::SplitNewlines(src,
[&](const AuString &src)
{
if (lines == 0)
{
@ -38,8 +40,12 @@ namespace Aurora::Crypto::PEM
}
str += src;
}
);
});
}
catch (...)
{
return false;
}
return fail ? false : finished;
}
@ -51,18 +57,26 @@ namespace Aurora::Crypto::PEM
ret += begin;
ret += delm;
AuString b64;
if (!Parse::Base64Encode(buf, b64))
try
{
if (!Parse::Base64Encode(buf, b64))
{
return "";
}
else
{
b64 = Parse::SplitStringDelm(b64, delm, 16);
}
ret += b64;
ret += delm;
ret += end;
return ret;
}
catch (...)
{
return "";
}
else
{
b64 = Parse::SplitStringDelm(b64, delm, 16);
}
ret += b64;
ret += delm;
ret += end;
return ret;
}
AUKN_SYM AuString ToString(const Aurora::Crypto::X509::Certificate &in)

View File

@ -19,6 +19,7 @@
#include "Debug/Debug.hpp"
#include "Async/Async.hpp"
#include "HWInfo/HWInfo.hpp"
#include "Telemetry/Telemetry.hpp"
#include "Threading/Threads/OSThread.hpp"
#if defined(AURORA_PLATFORM_WIN32)
#include "Extensions/Win32/DarkTheme.hpp"
@ -42,6 +43,7 @@ static void Init()
Aurora::Hashing::InitHashing();
Aurora::Async::InitAsync();
Aurora::HWInfo::Init();
Aurora::Telemetry::Init();
}
static void Pump()

View File

@ -60,6 +60,7 @@ namespace Aurora::Telemetry
void Init()
{
gGroupLock = AuThreadPrimitives::CriticalSectionUnique();
ReportSysInfo();
}

View File

View File