RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
CallbackSink.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <functional>
6#include <string_view>
7
8namespace RST::Log {
9
11 class CallbackSink : public ASink {
12 public:
13 using MessageCallback = std::function<void(const LogMessage&)>;
14 using LineCallback = std::function<void(LogLevel, std::string_view)>;
15
16 CallbackSink() = default;
17 explicit CallbackSink(MessageCallback callback);
18 explicit CallbackSink(LineCallback callback);
19
21 void setCallback(LineCallback callback);
23
24 [[nodiscard]] bool hasCallback();
25
26 protected:
27 void log(const LogMessage& message) override;
28
29 private:
30 MessageCallback _messageCallback;
31 LineCallback _lineCallback;
32 };
33
34}
Base class for sinks: handles the level, the pattern and the locking.
Definition ASink.hpp:17
Calls a function for each message, with the LogMessage or with the level and formatted line.
Definition CallbackSink.hpp:11
CallbackSink(MessageCallback callback)
void setCallback(LineCallback callback)
std::function< void(const LogMessage &)> MessageCallback
Definition CallbackSink.hpp:13
void setCallback(MessageCallback callback)
CallbackSink(LineCallback callback)
std::function< void(LogLevel, std::string_view)> LineCallback
Definition CallbackSink.hpp:14
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
LogLevel
Severity of a message, from Trace to Fatal; Off disables logging.
Definition LogLevel.hpp:11
A log record as passed to the sinks.
Definition LogMessage.hpp:18