[*] logger mitigations cont - current thread callback may as well be sanitized as well

This commit is contained in:
Reece Wilson 2023-04-18 02:30:11 +01:00
parent b32bf5f1f1
commit bfd4069994
2 changed files with 59 additions and 25 deletions

View File

@ -42,10 +42,7 @@ namespace Aurora::Logging
(msg.line.find('\r') == AuString::npos &&
msg.line.find('\33') == AuString::npos))) [[likely]]
{
if (WriteNow(uLevel, msg))
{
AddToPushQueueConst(uLevel, msg);
}
WriteNowConst(uLevel, msg);
}
else [[unlikely]]
{
@ -57,7 +54,7 @@ namespace Aurora::Logging
if (WriteNow(uLevel, dup))
{
AddToPushQueue(uLevel, dup);
AddToPushQueueConst(uLevel, dup);
}
});
}
@ -92,19 +89,6 @@ namespace Aurora::Logging
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);
}
@ -307,9 +291,11 @@ namespace Aurora::Logging
}
}
bool Logger::WriteNow(AuUInt8 uLevel, const ConsoleMessage &msg)
void Logger::WriteNowConst(AuUInt8 uLevel, const ConsoleMessage &msg)
{
bool ret {};
bool bDelegateLater {};
try
{
for (const auto &sink : this->sinks)
@ -321,7 +307,7 @@ namespace Aurora::Logging
try
{
ret |= sink->OnMessageNonblocking(uLevel, msg);
bDelegateLater |= sink->OnMessageNonblocking(uLevel, msg);
}
catch (...)
{
@ -331,10 +317,58 @@ namespace Aurora::Logging
}
catch (...)
{
ret = true;
bDelegateLater = true;
SysPushErrorCatch();
}
return ret;
if (bDelegateLater)
{
AddToPushQueueConst(uLevel, msg);
}
}
bool Logger::WriteNow(AuUInt8 uLevel, 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");
}
}
bool bDelegateLater {};
try
{
for (const auto &sink : this->sinks)
{
if (!sink)
{
continue;
}
try
{
bDelegateLater |= sink->OnMessageNonblocking(uLevel, msg);
}
catch (...)
{
SysPushErrorCatch("Failed to pump a logger");
}
}
}
catch (...)
{
bDelegateLater = true;
SysPushErrorCatch();
}
return bDelegateLater;
}
void Logger::WriteLater(AuUInt8 uLevel, const ConsoleMessage &msg)
@ -366,7 +400,6 @@ namespace Aurora::Logging
void InitLoggers()
{
gLogTasks.reserve(1000);
}

View File

@ -26,7 +26,8 @@ namespace Aurora::Logging
void AddToPushQueueConst(AuUInt8 level, const ConsoleMessage &msg);
void AddToPushQueue(AuUInt8 level, ConsoleMessage &msg);
bool WriteNow(AuUInt8 level, const ConsoleMessage &msg);
bool WriteNow(AuUInt8 level, ConsoleMessage &msg);
void WriteNowConst(AuUInt8 level, const ConsoleMessage &msg);
void WriteLater(AuUInt8 level, const ConsoleMessage &msg);
void WriteLines(AuUInt8 level, const ConsoleMessage &msg);