AuroraRuntime/Source/Console/ConsoleMessage.cpp
Reece 0c3344fe46 [+] IIOSimpleEventListener
[+] IOProcessor::StartSimpleIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener)
[+] IOProcessor::StartSimpleLSWatch(const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener)
[*] IOAdapterAsyncStream should reset the transactions IO state upon reaching end of segment (should this be per tick?) or upon stream error - otherwise, we end up spinning on a stuck event forever
[*] Fix non-linear path under read of the AuByteBuffer
[*] Fix various other nonlinear conditions under AuByteBuffer
[*] IOProcessor releases registered io item from queue upon request
[*] Fix ConsoleMessage::Write -> enumeration of color should be casted to a uint8
[+] Error telemetry under async task creation
[*] Fix various lock ups and non-blocking spins related to erroneous InternalRunOne impl. Residual preemptive batching was fucking with modern io.
[*] Cleanup TaskFrom/JobFrom. More work required to clean up legacy piss
2022-06-22 14:42:17 +01:00

134 lines
3.2 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ConsoleMessage.cpp
Date: 2021-6-12
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "ConsoleMessage.hpp"
#include "ColorConvert.hpp"
namespace Aurora::Console
{
static AuString StringifyTimeEx(const ConsoleMessage &msg, bool simple, bool utc)
{
try
{
std::tm localized;
Aurora::Time::ToCivilTime(msg.time, utc).CopyTo(localized);
if (simple)
{
return fmt::format("{:%H:%M:%S}", localized);
}
else
{
return fmt::format("{:%Y-%m-%d %H:%M:%S}", localized);
}
}
catch (...)
{
return {};
}
}
AUKN_SYM void ConsoleMessage::Read(Memory::ByteBuffer &deserialize)
{
AuUInt8 ref;
deserialize.Read(ref);
color = static_cast<EAnsiColor>(ref);
deserialize.Read(prefix);
deserialize.Read(line);
deserialize.Read(time);
deserialize.Read(tid);
}
AUKN_SYM void ConsoleMessage::Write(Memory::ByteBuffer &serialize) const
{
serialize.Write(static_cast<AuUInt8>(color));
serialize.Write(prefix);
serialize.Write(line);
serialize.Write(time);
serialize.Write(tid);
}
AuString ConsoleMessage::StringifyTime(bool simple) const
{
try
{
return StringifyTimeEx(*this, simple, false);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::StringifyTimeUTC() const
{
try
{
return StringifyTimeEx(*this, false, true);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::GetWrappedTag() const
{
return "[" + prefix + "]";
}
AuString ConsoleMessage::ToConsole() const
{
try
{
return fmt::format("{}[{}] {:<8} | {}{}",
static_cast<EAnsiColor>(color) <= EAnsiColor::eEnumCount ?
kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(color)] :
"",
StringifyTime(gRuntimeConfig.console.stdOutShortTime),
GetWrappedTag(),
line,
kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)]);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::ToPersistentString() const
{
try
{
return fmt::format("[{}] {:<7} | {}",
StringifyTimeUTC(),
GetWrappedTag(),
line);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::ToSimplified() const
{
try
{
return fmt::format("{:<9} {:<8} | {}", StringifyTime(true), GetWrappedTag(), line);
}
catch (...)
{
return {};
}
}
}