log_sink_set.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/internal/log_sink_set.h
  17. // -----------------------------------------------------------------------------
  18. #ifndef ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
  19. #define ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
  20. #include "absl/base/config.h"
  21. #include "absl/log/log_entry.h"
  22. #include "absl/log/log_sink.h"
  23. #include "absl/types/span.h"
  24. namespace absl {
  25. ABSL_NAMESPACE_BEGIN
  26. namespace log_internal {
  27. // Returns true if a globally-registered `LogSink`'s `Send()` is currently
  28. // being invoked on this thread.
  29. bool ThreadIsLoggingToLogSink();
  30. // This function may log to two sets of sinks:
  31. //
  32. // * If `extra_sinks_only` is true, it will dispatch only to `extra_sinks`.
  33. // `LogMessage::ToSinkAlso` and `LogMessage::ToSinkOnly` are used to attach
  34. // extra sinks to the entry.
  35. // * Otherwise it will also log to the global sinks set. This set is managed
  36. // by `absl::AddLogSink` and `absl::RemoveLogSink`.
  37. void LogToSinks(const absl::LogEntry& entry,
  38. absl::Span<absl::LogSink*> extra_sinks, bool extra_sinks_only);
  39. // Implementation for operations with log sink set.
  40. void AddLogSink(absl::LogSink* sink);
  41. void RemoveLogSink(absl::LogSink* sink);
  42. void FlushLogSinks();
  43. } // namespace log_internal
  44. ABSL_NAMESPACE_END
  45. } // namespace absl
  46. #endif // ABSL_LOG_INTERNAL_LOG_SINK_SET_H_