Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : //
3 : : // Licensed under the Apache License, Version 2.0 (the "License");
4 : : // you may not use this file except in compliance with the License.
5 : : // You may obtain a copy of the License at
6 : : //
7 : : // http://www.apache.org/licenses/LICENSE-2.0
8 : : //
9 : : // Unless required by applicable law or agreed to in writing, software
10 : : // distributed under the License is distributed on an "AS IS" BASIS,
11 : : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : // See the License for the specific language governing permissions and
13 : : // limitations under the License.
14 : :
15 : : #pragma once
16 : :
17 : : #include <atomic>
18 : : #include <memory>
19 : : #include <string>
20 : : #include <thread>
21 : : #include <vector>
22 : :
23 : : namespace hpactor::log {
24 : :
25 : : class LogRingBuffer;
26 : : class ILogFormatter;
27 : : class ILogSink;
28 : : struct LogConfig;
29 : :
30 : : class LogDrain {
31 : : public:
32 : : LogDrain(LogRingBuffer& buffer, ILogFormatter& formatter,
33 : : std::vector<std::unique_ptr<ILogSink>> sinks,
34 : : const LogConfig& config) noexcept;
35 : :
36 : : ~LogDrain();
37 : :
38 : : LogDrain(const LogDrain&) = delete;
39 : : LogDrain& operator=(const LogDrain&) = delete;
40 : :
41 : : void start();
42 : : void stop() noexcept;
43 : : void nudge() noexcept;
44 : :
45 : 0 : uint64_t sink_errors() const noexcept {
46 : 0 : return sink_errors_.load();
47 : : }
48 : :
49 : : private:
50 : : void run();
51 : :
52 : : LogRingBuffer& buffer_;
53 : : ILogFormatter& formatter_;
54 : : std::vector<std::unique_ptr<ILogSink>> sinks_;
55 : : const LogConfig& config_;
56 : :
57 : : std::thread thread_;
58 : : std::atomic<bool> running_{false};
59 : : std::atomic<uint64_t> sink_errors_{0};
60 : : };
61 : :
62 : : } // namespace hpactor::log
|