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 : : #include <cstdio>
16 : : #include <hpactor/log/log_sink.hpp>
17 : :
18 : : namespace hpactor::log {
19 : :
20 : : class StderrSink : public ILogSink {
21 : : public:
22 : 1 : result<void> write(std::string_view line) noexcept override {
23 : 1 : std::fwrite(line.data(), 1, line.size(), stderr);
24 : 1 : std::fputc('\n', stderr);
25 : 1 : return result<void>::make();
26 : : }
27 : :
28 : 1 : result<void> flush() noexcept override {
29 : 1 : std::fflush(stderr);
30 : 1 : return result<void>::make();
31 : : }
32 : : };
33 : :
34 : 2 : std::unique_ptr<ILogSink> make_stderr_sink() {
35 : 2 : return std::make_unique<StderrSink>();
36 : : }
37 : :
38 : : } // namespace hpactor::log
|