/src/abseil-cpp/absl/log/log_sink_registry.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2022 The Abseil Authors. |
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 | | // https://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 | | // ----------------------------------------------------------------------------- |
16 | | // File: log/log_sink_registry.h |
17 | | // ----------------------------------------------------------------------------- |
18 | | // |
19 | | // This header declares APIs to operate on global set of registered log sinks. |
20 | | |
21 | | #ifndef ABSL_LOG_LOG_SINK_REGISTRY_H_ |
22 | | #define ABSL_LOG_LOG_SINK_REGISTRY_H_ |
23 | | |
24 | | #include "absl/base/config.h" |
25 | | #include "absl/log/internal/log_sink_set.h" |
26 | | #include "absl/log/log_sink.h" |
27 | | |
28 | | namespace absl { |
29 | | ABSL_NAMESPACE_BEGIN |
30 | | |
31 | | // AddLogSink(), RemoveLogSink() |
32 | | // |
33 | | // Adds or removes a `absl::LogSink` as a consumer of logging data. |
34 | | // |
35 | | // These functions are thread-safe. |
36 | | // |
37 | | // It is an error to attempt to add a sink that's already registered or to |
38 | | // attempt to remove one that isn't. |
39 | | // |
40 | | // To avoid unbounded recursion, dispatch to registered `absl::LogSink`s is |
41 | | // disabled per-thread while running the `Send()` method of registered |
42 | | // `absl::LogSink`s. Affected messages are dispatched to a special internal |
43 | | // sink instead which writes them to `stderr`. |
44 | | // |
45 | | // Do not call these inside `absl::LogSink::Send`. |
46 | 0 | inline void AddLogSink(absl::LogSink* sink) { log_internal::AddLogSink(sink); } |
47 | 0 | inline void RemoveLogSink(absl::LogSink* sink) { |
48 | 0 | log_internal::RemoveLogSink(sink); |
49 | 0 | } |
50 | | |
51 | | // FlushLogSinks() |
52 | | // |
53 | | // Calls `absl::LogSink::Flush` on all registered sinks. |
54 | | // |
55 | | // Do not call this inside `absl::LogSink::Send`. |
56 | 0 | inline void FlushLogSinks() { log_internal::FlushLogSinks(); } |
57 | | |
58 | | ABSL_NAMESPACE_END |
59 | | } // namespace absl |
60 | | |
61 | | #endif // ABSL_LOG_LOG_SINK_REGISTRY_H_ |