RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
FileSink.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <fstream>
6#include <string>
7#include <string_view>
8
9namespace RST::Log {
10
12 class FileSink : public ASink {
13 public:
16 explicit FileSink(std::string_view filepath, bool truncate = false);
17 ~FileSink() override;
18
19 [[nodiscard]] const std::string& filepath() const noexcept { return _filepath; }
20
21 protected:
22 void log(const LogMessage& message) override;
23 void flushSink() override;
24
25 private:
26 std::string _filepath;
27 std::ofstream _file;
28 };
29
30}
Base class for sinks: handles the level, the pattern and the locking.
Definition ASink.hpp:17
Appends messages to a file.
Definition FileSink.hpp:12
void flushSink() override
Flushes the output; called with the sink mutex locked.
FileSink(std::string_view filepath, bool truncate=false)
Opens filepath, emptying it first if truncate is true.
void log(const LogMessage &message) override
Writes one message; called with the sink mutex locked.
const std::string & filepath() const noexcept
Definition FileSink.hpp:19
~FileSink() override
Thread-safe logging: loggers, sinks, patterns and macros.
Definition Terminal.hpp:8
A log record as passed to the sinks.
Definition LogMessage.hpp:18