/src/abseil-cpp/absl/log/log_sink.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.h  | 
17  |  | // -----------------------------------------------------------------------------  | 
18  |  | //  | 
19  |  | // This header declares the interface class `absl::LogSink`.  | 
20  |  |  | 
21  |  | #ifndef ABSL_LOG_LOG_SINK_H_  | 
22  |  | #define ABSL_LOG_LOG_SINK_H_  | 
23  |  |  | 
24  |  | #include "absl/base/config.h"  | 
25  |  | #include "absl/log/log_entry.h"  | 
26  |  |  | 
27  |  | namespace absl { | 
28  |  | ABSL_NAMESPACE_BEGIN  | 
29  |  |  | 
30  |  | // absl::LogSink  | 
31  |  | //  | 
32  |  | // `absl::LogSink` is an interface which can be extended to intercept and  | 
33  |  | // process particular messages (with `LOG.ToSinkOnly()` or  | 
34  |  | // `LOG.ToSinkAlso()`) or all messages (if registered with  | 
35  |  | // `absl::AddLogSink`).  Implementations must be thread-safe, and should take  | 
36  |  | // care not to take any locks that might be held by the `LOG` caller.  | 
37  |  | class LogSink { | 
38  |  |  public:  | 
39  | 0  |   virtual ~LogSink() = default;  | 
40  |  |  | 
41  |  |   // LogSink::Send()  | 
42  |  |   //  | 
43  |  |   // `Send` is called synchronously during the log statement.  | 
44  |  |   //  | 
45  |  |   // It is safe to use `LOG` within an implementation of `Send`.  `ToSinkOnly`  | 
46  |  |   // and `ToSinkAlso` are safe in general but can be used to create an infinite  | 
47  |  |   // loop if you try.  | 
48  |  |   virtual void Send(const absl::LogEntry& entry) = 0;  | 
49  |  |  | 
50  |  |   // LogSink::Flush()  | 
51  |  |   //  | 
52  |  |   // Sinks that buffer messages should override this method to flush the buffer  | 
53  |  |   // and return.  | 
54  | 0  |   virtual void Flush() {} | 
55  |  |  | 
56  |  |  private:  | 
57  |  |   // https://lld.llvm.org/missingkeyfunction.html#missing-key-function  | 
58  |  |   virtual void KeyFunction() const final;  // NOLINT(readability/inheritance)  | 
59  |  | };  | 
60  |  |  | 
61  |  | ABSL_NAMESPACE_END  | 
62  |  | }  // namespace absl  | 
63  |  |  | 
64  |  | #endif  // ABSL_LOG_LOG_SINK_H_  |