MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / CleanupOldLogs

Function CleanupOldLogs

TombEngine/Game/debug/debug.cpp:28–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 }
27
28 static void CleanupOldLogs(const std::filesystem::path& logDir)
29 {
30 std::vector<std::filesystem::directory_entry> logFiles;
31
32 if (!std::filesystem::exists(logDir))
33 return;
34
35 for (const auto& entry : std::filesystem::directory_iterator(logDir))
36 {
37 if (entry.is_regular_file() && entry.path().extension() == ".txt")
38 logFiles.push_back(entry);
39 }
40
41 if (logFiles.size() <= MAX_LOG_FILES)
42 return;
43
44 std::sort(logFiles.begin(), logFiles.end(),
45 [](const auto& a, const auto& b)
46 {
47 return std::filesystem::last_write_time(a) < std::filesystem::last_write_time(b);
48 });
49
50 // Delete oldest until we have MAX_LOG_FILES.
51 while (logFiles.size() > MAX_LOG_FILES)
52 {
53 try
54 {
55 std::filesystem::remove(logFiles.front());
56 }
57 catch (...) {}
58 logFiles.erase(logFiles.begin());
59 }
60 }
61
62 void InitTENLog(const std::string& logDirContainingDir)
63 {

Callers 1

InitTENLogFunction · 0.85

Calls 6

removeFunction · 0.85
push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected