RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
SessionFileSink.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6#include <fstream>
7#include <string>
8#include <string_view>
9
10namespace RST::Log {
11
13 class SessionFileSink : public ASink {
14 public:
15 static constexpr std::size_t DEFAULT_MAX_BACKUPS = 10;
16
20 explicit SessionFileSink(std::string_view filepath, std::size_t maxBackups = DEFAULT_MAX_BACKUPS);
21 ~SessionFileSink() override;
22
23 [[nodiscard]] const std::string& filepath() const noexcept { return _filepath; }
24
25 protected:
26 void log(const LogMessage& message) override;
27 void flushSink() override;
28
29 private:
30 std::string _filepath;
31 std::ofstream _file;
32 };
33
34}
Base class for sinks: handles the level, the pattern and the locking.
Definition ASink.hpp:17
Writes one file per run, keeping the files of the previous runs as backups.
Definition SessionFileSink.hpp:13
void flushSink() override
Flushes the output; called with the sink mutex locked.
SessionFileSink(std::string_view filepath, std::size_t maxBackups=DEFAULT_MAX_BACKUPS)
Opens filepath, first renaming the file of the previous run to a dated -backup- copy.
static constexpr std::size_t DEFAULT_MAX_BACKUPS
Definition SessionFileSink.hpp:15
const std::string & filepath() const noexcept
Definition SessionFileSink.hpp:23
void log(const LogMessage &message) override
Writes one message; called with the sink mutex locked.
Thread-safe logging: loggers, sinks, patterns and macros.
Definition Terminal.hpp:8
A log record as passed to the sinks.
Definition LogMessage.hpp:18