Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 08:06:41

0001 // Copyright 2022 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 //
0015 // -----------------------------------------------------------------------------
0016 // File: log/log_sink.h
0017 // -----------------------------------------------------------------------------
0018 //
0019 // This header declares the interface class `absl::LogSink`.
0020 
0021 #ifndef ABSL_LOG_LOG_SINK_H_
0022 #define ABSL_LOG_LOG_SINK_H_
0023 
0024 #include "absl/base/config.h"
0025 #include "absl/log/log_entry.h"
0026 
0027 namespace absl {
0028 ABSL_NAMESPACE_BEGIN
0029 
0030 // absl::LogSink
0031 //
0032 // `absl::LogSink` is an interface which can be extended to intercept and
0033 // process particular messages (with `LOG.ToSinkOnly()` or
0034 // `LOG.ToSinkAlso()`) or all messages (if registered with
0035 // `absl::AddLogSink`).  Implementations must not take any locks that might be
0036 // held by the `LOG` caller.
0037 class LogSink {
0038  public:
0039   virtual ~LogSink() = default;
0040 
0041   // LogSink::Send()
0042   //
0043   // `Send` is called synchronously during the log statement.  `Send` must be
0044   // thread-safe.
0045   //
0046   // It is safe to use `LOG` within an implementation of `Send`.  `ToSinkOnly`
0047   // and `ToSinkAlso` are safe in general but can be used to create an infinite
0048   // loop if you try.
0049   virtual void Send(const absl::LogEntry& entry) = 0;
0050 
0051   // LogSink::Flush()
0052   //
0053   // Sinks that buffer messages should override this method to flush the buffer
0054   // and return.  `Flush` must be thread-safe.
0055   virtual void Flush() {}
0056 
0057  protected:
0058   LogSink() = default;
0059   // Implementations may be copyable and/or movable.
0060   LogSink(const LogSink&) = default;
0061   LogSink& operator=(const LogSink&) = default;
0062 
0063  private:
0064   // https://lld.llvm.org/missingkeyfunction.html#missing-key-function
0065   virtual void KeyFunction() const final;  // NOLINT(readability/inheritance)
0066 };
0067 
0068 ABSL_NAMESPACE_END
0069 }  // namespace absl
0070 
0071 #endif  // ABSL_LOG_LOG_SINK_H_