Add configurable split file logging

This commit is contained in:
faumaray committed 2026-08-02 01:47:22 +03:00
1 parent 8531bea681
commit 531b604154
3 files changed
+68 -8

No files matched your search

+30 -2
View File
@@ -38,6 +38,19 @@ namespace
}
return count;
}
std::size_t snapshot_count(const std::filesystem::path& dir)
{
const auto history = dir / "history";
if (!std::filesystem::exists(history)) {
return 0;
}
std::size_t count = 0;
for (const auto& entry : std::filesystem::directory_iterator(history)) {
count += entry.is_directory() ? 1U : 0U;
}
return count;
}
} // namespace
class SplitFileLoggerTests : public Void::Testing::Fixture
@@ -81,7 +94,7 @@ class SplitFileLoggerTests : public Void::Testing::Fixture
log.info("info one");
log.error("error one");
}
const auto all = slurp(dir / "trace.log");
const auto all = slurp(dir / "all.log");
Void::Testing::expect(all.find("info one") != std::string::npos);
Void::Testing::expect(all.find("error one") != std::string::npos);
}
@@ -94,9 +107,24 @@ class SplitFileLoggerTests : public Void::Testing::Fixture
.mode = Void::Logging::Mode::Immediate}};
log.info("solo");
}
Void::Testing::expect(!std::filesystem::exists(dir / "trace.log"));
Void::Testing::expect(!std::filesystem::exists(dir / "all.log"));
Void::Testing::expect(std::filesystem::exists(dir / "info.log"));
}
Void::Testing::Test bounds_synchronized_history()
{
{
SplitFileLogger log{dir,
{.max_bytes = 32,
.max_files = 2,
.mode = Void::Logging::Mode::Immediate}};
for (int i = 0; i < 20; ++i) {
log.info("rotation payload " + std::to_string(i));
}
}
Void::Testing::expect(snapshot_count(dir) >= 1);
Void::Testing::expect(snapshot_count(dir) <= 2);
}
};
class HistoryLoggerTests : public Void::Testing::Fixture