log_sink_set.h 2.0 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 Y_ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
  19. #define Y_ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
  20. #include "y_absl/base/config.h"
  21. #include "y_absl/log/log_entry.h"
  22. #include "y_absl/log/log_sink.h"
  23. #include "y_absl/types/span.h"
  24. namespace y_absl {
  25. Y_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 `y_absl::AddLogSink` and `y_absl::RemoveLogSink`.
  37. void LogToSinks(const y_absl::LogEntry& entry,
  38. y_absl::Span<y_absl::LogSink*> extra_sinks, bool extra_sinks_only);
  39. // Implementation for operations with log sink set.
  40. void AddLogSink(y_absl::LogSink* sink);
  41. void RemoveLogSink(y_absl::LogSink* sink);
  42. void FlushLogSinks();
  43. } // namespace log_internal
  44. Y_ABSL_NAMESPACE_END
  45. } // namespace y_absl
  46. #endif // Y_ABSL_LOG_INTERNAL_LOG_SINK_SET_H_