Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
19 files changed
+579
-10
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <Logging/Sink.hpp>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace vl::logging {
|
||||
|
||||
// File rotation: R3 (daily + index), plus optional size cap
|
||||
class FileSink final : public Sink {
|
||||
public:
|
||||
explicit FileSink(std::string basePath, std::uintmax_t maxBytes);
|
||||
|
||||
void write(const Message& msg) override;
|
||||
|
||||
private:
|
||||
std::string base_;
|
||||
std::uintmax_t maxBytes_;
|
||||
std::ofstream out_;
|
||||
std::string currentDate_; // YYYY-MM-DD
|
||||
int index_{1};
|
||||
std::uintmax_t written_{0};
|
||||
|
||||
void ensureOpen(const Message& msg);
|
||||
void openCurrent();
|
||||
void rotateToDate(std::string newDate);
|
||||
|
||||
static std::string dateOf(const std::chrono::system_clock::time_point& tp);
|
||||
static std::string filenameFor(const std::string& base, std::string_view date, int index);
|
||||
};
|
||||
|
||||
} // namespace vl::log
|
||||
Reference in new issue
Block a user