numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
combined_log_sink.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <string_view>
23#include <utility>
24#include <vector>
25
30
32
39public:
46 std::vector<std::pair<log_sink, log_level>> sinks)
47 : sinks_(std::move(sinks)) {}
48
52 ~combined_log_sink() = default;
53
54 combined_log_sink(const combined_log_sink&) = delete;
56 auto operator=(const combined_log_sink&) -> combined_log_sink& = delete;
57 auto operator=(combined_log_sink&&) -> combined_log_sink& = delete;
58
70 void write(time_stamp time, std::string_view tag, log_level level,
71 util::source_info_view source, std::string_view body) noexcept {
72 for (const auto& [sink, output_log_level] : sinks_) {
73 if (level >= output_log_level) {
74 sink.write(time, tag, level, source, body);
75 }
76 }
77 }
78
79private:
81 std::vector<std::pair<log_sink, log_level>> sinks_;
82};
83
90[[nodiscard]] inline auto create_combined_log_sink(
91 std::vector<std::pair<log_sink, log_level>> sinks) -> log_sink {
92 return create_log_sink<combined_log_sink>(std::move(sinks));
93}
94
95} // namespace num_collect::logging::sinks
Class of log sinks to write logs to multiple log sinks.
combined_log_sink(std::vector< std::pair< log_sink, log_level > > sinks)
Constructor.
std::vector< std::pair< log_sink, log_level > > sinks_
Log sinks with log levels.
void write(time_stamp time, std::string_view tag, log_level level, util::source_info_view source, std::string_view body) noexcept
Write a log.
Class of time stamps.
Definition time_stamp.h:38
Class to hold information of source codes.
Definition of log_level enumeration.
Definition of log_sink class.
Namespace of log sinks.
auto create_combined_log_sink(std::vector< std::pair< log_sink, log_level > > sinks) -> log_sink
Create a log sink to write logs to multiple log sinks.
auto create_log_sink(Args &&... args) -> log_sink
Create a log sink.
Definition log_sink.h:146
log_level
Enumeration of log levels.
Definition log_level.h:47
STL namespace.
Definition of source_info_view class.
Definition of time_stamp class.