change rotation
CI / GCC 16 / C++26 / default (push) Has been cancelled
CI / GCC 16 / C++26 / sanitizers (push) Has been cancelled
CI / GCC 16 / C++26 / werror (push) Has been cancelled

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-06 14:42:28 +03:00
1 parent a4f52cf174
commit 827c9e150a
7 files changed
+221 -33

No files matched your search

+34 -4
View File
@@ -24,7 +24,8 @@ namespace Void::Logging
SplitFileLogger::SplitFileLogger(std::filesystem::path dir, Options options)
: Logger(options.mode, options.capacity, options.policy),
m_dir(std::move(dir)), m_options(options)
m_dir(std::move(dir)), m_options(options),
m_epoch_start(std::chrono::system_clock::now())
{
std::error_code ec;
std::filesystem::create_directories(m_dir, ec);
@@ -34,9 +35,10 @@ namespace Void::Logging
}
if (m_options.combined) {
m_combined = std::make_unique<Detail::RollingFile>(
m_dir / "all.log",
m_dir / "trace.log",
Detail::RollingFileOptions{m_options.max_bytes,
m_options.max_files});
m_options.max_files},
/*self_rotate=*/false);
(void)m_combined->open();
}
Void::Log::debug("Log.Split", "split logging into '{}'",
@@ -63,7 +65,8 @@ namespace Void::Logging
Detail::RollingFile file{
m_dir / level_filename(level),
Detail::RollingFileOptions{m_options.max_bytes,
m_options.max_files}};
m_options.max_files},
/*self_rotate=*/false};
(void)file.open();
it = m_per_level.emplace(level, std::move(file)).first;
}
@@ -83,6 +86,33 @@ namespace Void::Logging
if (m_combined) {
m_combined->write(line);
}
maybe_rotate_group();
}
void SplitFileLogger::maybe_rotate_group()
{
bool any_exceeds = m_combined && m_combined->exceeds_limit();
if (!any_exceeds) {
for (const auto& [level, file] : m_per_level) {
if (file.exceeds_limit()) {
any_exceeds = true;
break;
}
}
}
if (!any_exceeds) {
return;
}
const auto snapshot_dir =
m_dir / "history" / Detail::format_timestamp(m_epoch_start);
for (auto& [level, file] : m_per_level) {
file.snapshot_into(snapshot_dir);
}
if (m_combined) {
m_combined->snapshot_into(snapshot_dir);
}
m_epoch_start = std::chrono::system_clock::now();
}
void SplitFileLogger::write(const Entry& entry)