1*9356374aSAndroid Build Coastguard Worker // Copyright 2022 The Abseil Authors. 2*9356374aSAndroid Build Coastguard Worker // 3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*9356374aSAndroid Build Coastguard Worker // 7*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0 8*9356374aSAndroid Build Coastguard Worker // 9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*9356374aSAndroid Build Coastguard Worker // limitations under the License. 14*9356374aSAndroid Build Coastguard Worker // 15*9356374aSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------- 16*9356374aSAndroid Build Coastguard Worker // File: log/log_sink.h 17*9356374aSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------- 18*9356374aSAndroid Build Coastguard Worker // 19*9356374aSAndroid Build Coastguard Worker // This header declares the interface class `absl::LogSink`. 20*9356374aSAndroid Build Coastguard Worker 21*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_LOG_LOG_SINK_H_ 22*9356374aSAndroid Build Coastguard Worker #define ABSL_LOG_LOG_SINK_H_ 23*9356374aSAndroid Build Coastguard Worker 24*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h" 25*9356374aSAndroid Build Coastguard Worker #include "absl/log/log_entry.h" 26*9356374aSAndroid Build Coastguard Worker 27*9356374aSAndroid Build Coastguard Worker namespace absl { 28*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN 29*9356374aSAndroid Build Coastguard Worker 30*9356374aSAndroid Build Coastguard Worker // absl::LogSink 31*9356374aSAndroid Build Coastguard Worker // 32*9356374aSAndroid Build Coastguard Worker // `absl::LogSink` is an interface which can be extended to intercept and 33*9356374aSAndroid Build Coastguard Worker // process particular messages (with `LOG.ToSinkOnly()` or 34*9356374aSAndroid Build Coastguard Worker // `LOG.ToSinkAlso()`) or all messages (if registered with 35*9356374aSAndroid Build Coastguard Worker // `absl::AddLogSink`). Implementations must not take any locks that might be 36*9356374aSAndroid Build Coastguard Worker // held by the `LOG` caller. 37*9356374aSAndroid Build Coastguard Worker class LogSink { 38*9356374aSAndroid Build Coastguard Worker public: 39*9356374aSAndroid Build Coastguard Worker virtual ~LogSink() = default; 40*9356374aSAndroid Build Coastguard Worker 41*9356374aSAndroid Build Coastguard Worker // LogSink::Send() 42*9356374aSAndroid Build Coastguard Worker // 43*9356374aSAndroid Build Coastguard Worker // `Send` is called synchronously during the log statement. `Send` must be 44*9356374aSAndroid Build Coastguard Worker // thread-safe. 45*9356374aSAndroid Build Coastguard Worker // 46*9356374aSAndroid Build Coastguard Worker // It is safe to use `LOG` within an implementation of `Send`. `ToSinkOnly` 47*9356374aSAndroid Build Coastguard Worker // and `ToSinkAlso` are safe in general but can be used to create an infinite 48*9356374aSAndroid Build Coastguard Worker // loop if you try. 49*9356374aSAndroid Build Coastguard Worker virtual void Send(const absl::LogEntry& entry) = 0; 50*9356374aSAndroid Build Coastguard Worker 51*9356374aSAndroid Build Coastguard Worker // LogSink::Flush() 52*9356374aSAndroid Build Coastguard Worker // 53*9356374aSAndroid Build Coastguard Worker // Sinks that buffer messages should override this method to flush the buffer 54*9356374aSAndroid Build Coastguard Worker // and return. `Flush` must be thread-safe. Flush()55*9356374aSAndroid Build Coastguard Worker virtual void Flush() {} 56*9356374aSAndroid Build Coastguard Worker 57*9356374aSAndroid Build Coastguard Worker protected: 58*9356374aSAndroid Build Coastguard Worker LogSink() = default; 59*9356374aSAndroid Build Coastguard Worker // Implementations may be copyable and/or movable. 60*9356374aSAndroid Build Coastguard Worker LogSink(const LogSink&) = default; 61*9356374aSAndroid Build Coastguard Worker LogSink& operator=(const LogSink&) = default; 62*9356374aSAndroid Build Coastguard Worker 63*9356374aSAndroid Build Coastguard Worker private: 64*9356374aSAndroid Build Coastguard Worker // https://lld.llvm.org/missingkeyfunction.html#missing-key-function 65*9356374aSAndroid Build Coastguard Worker virtual void KeyFunction() const final; // NOLINT(readability/inheritance) 66*9356374aSAndroid Build Coastguard Worker }; 67*9356374aSAndroid Build Coastguard Worker 68*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END 69*9356374aSAndroid Build Coastguard Worker } // namespace absl 70*9356374aSAndroid Build Coastguard Worker 71*9356374aSAndroid Build Coastguard Worker #endif // ABSL_LOG_LOG_SINK_H_ 72