[*] Logger mitigations

Closes #47
This commit is contained in:
Reece Wilson 2023-04-18 02:09:16 +01:00
parent b2311a8824
commit b32bf5f1f1
3 changed files with 41 additions and 9 deletions

View File

@ -33,6 +33,8 @@ namespace Aurora::Logging
virtual void PushFilter(AuUInt8 level, bool shouldFilter) = 0;
virtual void PopFilter() = 0;
virtual bool ExchangeMitigationState(bool bMitigationsEnabled) = 0;
#if defined(_AUHAS_FMT)
template<typename ... T>
inline void WriteLinef(AuUInt8 level, const AuString &tag, const AuString &msg, T&& ... args)

View File

@ -37,13 +37,15 @@ namespace Aurora::Logging
{
try
{
if (msg.line.find('\n') == AuString::npos) [[likely]]
if (msg.line.find('\n') == AuString::npos &&
((!this->bEnableMitigations) ||
(msg.line.find('\r') == AuString::npos &&
msg.line.find('\33') == AuString::npos))) [[likely]]
{
if (WriteNow(uLevel, msg))
{
AddToPushQueue(uLevel, msg);
AddToPushQueueConst(uLevel, msg);
}
}
else [[unlikely]]
{
@ -83,7 +85,30 @@ namespace Aurora::Logging
WriteLines(uLevel, msg);
}
void Logger::AddToPushQueue(AuUInt8 uLevel, const ConsoleMessage &msg)
bool Logger::ExchangeMitigationState(bool bMitigationsEnabled)
{
return AuExchange(this->bEnableMitigations, bMitigationsEnabled);
}
void Logger::AddToPushQueue(AuUInt8 uLevel, /*const*/ ConsoleMessage &msg)
{
if (this->bEnableMitigations)
{
if (msg.line.find('\r') != AuString::npos) [[unlikely]]
{
AuReplaceAll(msg.line, "\r", "\\r");
}
if (msg.line.find('\33') != AuString::npos) [[unlikely]]
{
AuReplaceAll(msg.line, "\33", "\\e");
}
}
AddToPushQueueConst(uLevel, msg);
}
void Logger::AddToPushQueueConst(AuUInt8 uLevel, const ConsoleMessage &msg)
{
{
AU_LOCK_GUARD(gTaskSpin);
@ -91,14 +116,14 @@ namespace Aurora::Logging
auto nice = gLogTasks.size() + 1;
if (gLogTasks.capacity() < nice)
{
gLogTasks.reserve(nice*10);
gLogTasks.reserve(nice * 10);
}
while (!AuTryInsert(gLogTasks, AuMakeTuple(this, uLevel, msg)))
while (!AuTryInsert(gLogTasks, AuMakeTuple(this, uLevel, AuConstReference(msg))))
{
SysPushErrorMem("Push failed - trying again");
spin.Unlock();
AuThreading::Sleep(100);
AuThreading::ContextYield();
spin.Lock();
}
}
@ -115,7 +140,7 @@ namespace Aurora::Logging
while (!AuTryInsert(filters, AuMakeTuple(uLevel, shouldFilter)))
{
SysPushErrorMem("Push failed - trying again. wont be able to handle pop - wont syspanic yet");
AuThreading::Sleep(100);
AuThreading::ContextYield();
}
AuMemset(this->shouldFilter, 0, sizeof(this->shouldFilter));

View File

@ -21,7 +21,11 @@ namespace Aurora::Logging
void PushFilter(AuUInt8 level, bool shouldFilter) override;
void PopFilter() override;
void AddToPushQueue(AuUInt8 level, const ConsoleMessage &msg);
bool ExchangeMitigationState(bool bMitigationsEnabled) override;
void AddToPushQueueConst(AuUInt8 level, const ConsoleMessage &msg);
void AddToPushQueue(AuUInt8 level, ConsoleMessage &msg);
bool WriteNow(AuUInt8 level, const ConsoleMessage &msg);
void WriteLater(AuUInt8 level, const ConsoleMessage &msg);
void WriteLines(AuUInt8 level, const ConsoleMessage &msg);
@ -32,6 +36,7 @@ namespace Aurora::Logging
AuList<AuSPtr<IBasicSink>> sinks;
AuList<AuTuple<AuUInt8, bool>> filters; // std::vector > std::stack performance. dont ask me why or for the benchmarks, just trust me bro
AuUInt8 shouldFilter[0xFF];
bool bEnableMitigations { true };
};
AuThreadPrimitives::SpinLock &GetLock();