log_sink_registry.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_registry.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This header declares APIs to operate on global set of registered log sinks.
  20. #ifndef ABSL_LOG_LOG_SINK_REGISTRY_H_
  21. #define ABSL_LOG_LOG_SINK_REGISTRY_H_
  22. #include "absl/base/config.h"
  23. #include "absl/log/internal/log_sink_set.h"
  24. #include "absl/log/log_sink.h"
  25. namespace absl {
  26. ABSL_NAMESPACE_BEGIN
  27. // AddLogSink(), RemoveLogSink()
  28. //
  29. // Adds or removes a `absl::LogSink` as a consumer of logging data.
  30. //
  31. // These functions are thread-safe.
  32. //
  33. // It is an error to attempt to add a sink that's already registered or to
  34. // attempt to remove one that isn't.
  35. //
  36. // To avoid unbounded recursion, dispatch to registered `absl::LogSink`s is
  37. // disabled per-thread while running the `Send()` method of registered
  38. // `absl::LogSink`s. Affected messages are dispatched to a special internal
  39. // sink instead which writes them to `stderr`.
  40. //
  41. // Do not call these inside `absl::LogSink::Send`.
  42. inline void AddLogSink(absl::LogSink* sink) { log_internal::AddLogSink(sink); }
  43. inline void RemoveLogSink(absl::LogSink* sink) {
  44. log_internal::RemoveLogSink(sink);
  45. }
  46. // FlushLogSinks()
  47. //
  48. // Calls `absl::LogSink::Flush` on all registered sinks.
  49. //
  50. // Do not call this inside `absl::LogSink::Send`.
  51. inline void FlushLogSinks() { log_internal::FlushLogSinks(); }
  52. ABSL_NAMESPACE_END
  53. } // namespace absl
  54. #endif // ABSL_LOG_LOG_SINK_REGISTRY_H_