3 Commits
Author SHA1 Message Date
faumaray d95e11ea3e Prepare VoidLibrary 1.2.0
Release / release (push) Successful in 27m41s
2026-08-02 02:07:30 +03:00
faumaray 531b604154 Add configurable split file logging 2026-08-02 01:47:22 +03:00
faumaray 8531bea681 Use organization release token 2026-08-01 20:12:32 +03:00
5 changed files with 70 additions and 10 deletions

No files matched your search

+1 -1
View File
@@ -82,7 +82,7 @@ jobs:
- name: Publish native Gitea release - name: Publish native Gitea release
env: env:
GITEA_RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
run: | run: |
python3 .release-tools/scripts/gitea_release.py \ python3 .release-tools/scripts/gitea_release.py \
--api-url "${{ gitea.api_url }}" \ --api-url "${{ gitea.api_url }}" \
+1 -1
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 4.0.0) cmake_minimum_required(VERSION 4.0.0)
project(Void VERSION 1.1.0 LANGUAGES CXX) project(Void VERSION 1.2.0 LANGUAGES CXX)
if(PROJECT_IS_TOP_LEVEL) if(PROJECT_IS_TOP_LEVEL)
option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON) option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON)
elseif(NOT DEFINED BUILD_SHARED_LIBS) elseif(NOT DEFINED BUILD_SHARED_LIBS)
+5 -5
View File
@@ -22,9 +22,8 @@ namespace Void::Logging
/// to the per-level files. /// to the per-level files.
bool combined = true; bool combined = true;
std::size_t max_bytes = 1024 * 1024; std::size_t max_bytes = 1024 * 1024;
/// Unused. Rotation here is a synchronized, unbounded history /// Maximum number of synchronized history snapshots retained.
/// (see class comment) rather than a max_files-bounded rotation, /// Zero removes a snapshot immediately after rotation.
/// so this has no effect — kept only for API compatibility.
std::size_t max_files = 5; std::size_t max_files = 5;
Mode mode = Mode::Async; Mode mode = Mode::Async;
std::size_t capacity = 512; std::size_t capacity = 512;
@@ -43,8 +42,8 @@ namespace Void::Logging
/// ones well under the limit) is moved, under its own name unchanged, /// ones well under the limit) is moved, under its own name unchanged,
/// into `<dir>/history/<creation_time>/`, where `<creation_time>` /// into `<dir>/history/<creation_time>/`, where `<creation_time>`
/// marks when this batch of files started filling up. Fresh, empty /// marks when this batch of files started filling up. Fresh, empty
/// files then continue at their usual paths. Every snapshot is kept /// files then continue at their usual paths. The oldest snapshots are
/// indefinitely — see SplitFileOptions::max_files. /// pruned so at most SplitFileOptions::max_files remain.
class SplitFileLogger final : public Logger class SplitFileLogger final : public Logger
{ {
public: public:
@@ -91,6 +90,7 @@ namespace Void::Logging
/// owned file into a shared history/<creation_time> snapshot /// owned file into a shared history/<creation_time> snapshot
/// directory and start each one fresh. /// directory and start each one fresh.
void maybe_rotate_group(); void maybe_rotate_group();
void prune_history();
std::filesystem::path m_dir; std::filesystem::path m_dir;
Options m_options; Options m_options;
+33 -1
View File
@@ -1,10 +1,12 @@
#include <Void/Log/SplitFileLogger.hpp> #include <Void/Log/SplitFileLogger.hpp>
#include <Void/Log/Log.hpp> #include <Void/Log/Log.hpp>
#include <algorithm>
#include <cctype> #include <cctype>
#include <format> #include <format>
#include <stdexcept> #include <stdexcept>
#include <system_error> #include <system_error>
#include <vector>
namespace Void::Logging namespace Void::Logging
{ {
@@ -35,7 +37,7 @@ namespace Void::Logging
} }
if (m_options.combined) { if (m_options.combined) {
m_combined = std::make_unique<Detail::RollingFile>( m_combined = std::make_unique<Detail::RollingFile>(
m_dir / "trace.log", m_dir / "all.log",
Detail::RollingFileOptions{m_options.max_bytes, Detail::RollingFileOptions{m_options.max_bytes,
m_options.max_files}, m_options.max_files},
/*self_rotate=*/false); /*self_rotate=*/false);
@@ -113,6 +115,36 @@ namespace Void::Logging
m_combined->snapshot_into(snapshot_dir); m_combined->snapshot_into(snapshot_dir);
} }
m_epoch_start = std::chrono::system_clock::now(); m_epoch_start = std::chrono::system_clock::now();
prune_history();
}
void SplitFileLogger::prune_history()
{
const auto history_dir = m_dir / "history";
std::error_code ec;
if (!std::filesystem::exists(history_dir, ec) || ec) {
return;
}
std::vector<std::filesystem::path> snapshots;
for (std::filesystem::directory_iterator it{history_dir, ec}, end;
!ec && it != end; it.increment(ec)) {
if (it->is_directory(ec) && !ec) {
snapshots.push_back(it->path());
}
}
if (ec) {
return;
}
std::ranges::sort(snapshots);
while (snapshots.size() > m_options.max_files) {
std::filesystem::remove_all(snapshots.front(), ec);
if (ec) {
return;
}
snapshots.erase(snapshots.begin());
}
} }
void SplitFileLogger::write(const Entry& entry) void SplitFileLogger::write(const Entry& entry)
+30 -2
View File
@@ -38,6 +38,19 @@ namespace
} }
return count; 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 } // namespace
class SplitFileLoggerTests : public Void::Testing::Fixture class SplitFileLoggerTests : public Void::Testing::Fixture
@@ -81,7 +94,7 @@ class SplitFileLoggerTests : public Void::Testing::Fixture
log.info("info one"); log.info("info one");
log.error("error 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("info one") != std::string::npos);
Void::Testing::expect(all.find("error 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}}; .mode = Void::Logging::Mode::Immediate}};
log.info("solo"); 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::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 class HistoryLoggerTests : public Void::Testing::Fixture