From 5f9fcce0a15fe3c8c0e4644c6b52c325c56e42db Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Thu, 6 Jul 2023 21:26:29 +0100 Subject: [PATCH] [*] fixed logic in dirlogarchive todo: get around to improving dirlogarchive --- Source/Logging/Sinks/DirLogArchive.cpp | 54 ++++++++++---------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/Source/Logging/Sinks/DirLogArchive.cpp b/Source/Logging/Sinks/DirLogArchive.cpp index 3ecec169..55b40ad1 100644 --- a/Source/Logging/Sinks/DirLogArchive.cpp +++ b/Source/Logging/Sinks/DirLogArchive.cpp @@ -17,7 +17,7 @@ namespace Aurora::Logging::Sinks AuList> fileMeta; AuUInt64 qwSize {}; - auto doScan = [&]() + auto doScan = [&](bool bOrder) { files.clear(); fileMeta.clear(); @@ -33,16 +33,23 @@ namespace Aurora::Logging::Sinks qwSize += stat.uSize; } - std::sort(fileMeta.begin(), fileMeta.end(), [](AuPair a, AuPair b) + std::sort(fileMeta.begin(), fileMeta.end(), [=](AuPair a, AuPair b) { - return AuGet<1>(a).modifiedNs < AuGet<1>(b).modifiedNs; + if (bOrder) + { + return AuGet<1>(a).modifiedNs < AuGet<1>(b).modifiedNs; + } + else + { + return AuGet<1>(a).modifiedNs > AuGet<1>(b).modifiedNs; + } }); }; - doScan(); - if (logger.uMaxLogsOrZeroBeforeCompress) { + doScan(false); + if (fileMeta.size() > logger.uMaxLogsOrZeroBeforeCompress) { for (AuUInt i = logger.uMaxLogsOrZeroBeforeCompress; i < fileMeta.size(); i++) @@ -57,14 +64,14 @@ namespace Aurora::Logging::Sinks } } - doScan(); } } if (logger.uMaxFileTimeInDeltaMSOrZeroBeforeCompress) { + doScan(true); + auto qwMaxTime = AuTime::CurrentClockMS() - logger.uMaxFileTimeInDeltaMSOrZeroBeforeCompress; - bool bRescan {}; for (AuUInt i = 0; i < fileMeta.size(); i++) { @@ -78,20 +85,13 @@ namespace Aurora::Logging::Sinks { AuIOFS::Remove(path); } - - bRescan = true; } } - - if (bRescan) - { - doScan(); - } } if (logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeCompress) { - bool bRescan {}; + doScan(false); if (qwSize > logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeCompress) { @@ -115,33 +115,26 @@ namespace Aurora::Logging::Sinks { AuIOFS::Remove(path); } - - bRescan = true; } } - - if (bRescan) - { - doScan(); - } } - + if (logger.uMaxLogsOrZeroBeforeDelete) { + doScan(false); + if (fileMeta.size() > logger.uMaxLogsOrZeroBeforeDelete) { for (AuUInt i = logger.uMaxLogsOrZeroBeforeDelete; i < fileMeta.size(); i++) { AuIOFS::Remove(baseLogPath + "/" + fileMeta[i].first); } - - doScan(); } } if (logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeDelete) { - bool bRescan {}; + doScan(false); if (qwSize > logger.uMaxCumulativeFileSizeInMiBOrZeroBeforeDelete) { @@ -160,20 +153,15 @@ namespace Aurora::Logging::Sinks if (AuIOFS::Remove(baseLogPath + "/" + fileMeta[i].first)) { qwSize -= fileMeta[i].second.uSize; - bRescan = true; } } - - } - - if (bRescan) - { - doScan(); } } if (logger.uMaxFileTimeInDeltaMSOrZeroBeforeDelete) { + doScan(true); + auto qwMaxTime = AuTime::CurrentClockMS() - logger.uMaxFileTimeInDeltaMSOrZeroBeforeDelete; for (AuUInt i = 0; i < fileMeta.size(); i++)