globals.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/globals.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This header file contains various global objects and static helper routines
  20. // use in logging implementation.
  21. #ifndef Y_ABSL_LOG_INTERNAL_GLOBALS_H_
  22. #define Y_ABSL_LOG_INTERNAL_GLOBALS_H_
  23. #include "y_absl/base/config.h"
  24. #include "y_absl/base/log_severity.h"
  25. #include "y_absl/strings/string_view.h"
  26. #include "y_absl/time/time.h"
  27. namespace y_absl {
  28. Y_ABSL_NAMESPACE_BEGIN
  29. namespace log_internal {
  30. // IsInitialized returns true if the logging library is initialized.
  31. // This function is async-signal-safe
  32. bool IsInitialized();
  33. // SetLoggingInitialized is called once after logging initialization is done.
  34. void SetInitialized();
  35. // Unconditionally write a `message` to stderr. If `severity` exceeds kInfo
  36. // we also flush the stderr stream.
  37. void WriteToStderr(y_absl::string_view message, y_absl::LogSeverity severity);
  38. // Set the TimeZone used for human-friendly times (for example, the log message
  39. // prefix) printed by the logging library. This may only be called once.
  40. void SetTimeZone(y_absl::TimeZone tz);
  41. // Returns the TimeZone used for human-friendly times (for example, the log
  42. // message prefix) printed by the logging library Returns nullptr prior to
  43. // initialization.
  44. const y_absl::TimeZone* TimeZone();
  45. // Returns true if stack traces emitted by the logging library should be
  46. // symbolized. This function is async-signal-safe.
  47. bool ShouldSymbolizeLogStackTrace();
  48. // Enables or disables symbolization of stack traces emitted by the
  49. // logging library. This function is async-signal-safe.
  50. void EnableSymbolizeLogStackTrace(bool on_off);
  51. // Returns the maximum number of frames that appear in stack traces
  52. // emitted by the logging library. This function is async-signal-safe.
  53. int MaxFramesInLogStackTrace();
  54. // Sets the maximum number of frames that appear in stack traces emitted by
  55. // the logging library. This function is async-signal-safe.
  56. void SetMaxFramesInLogStackTrace(int max_num_frames);
  57. // Determines whether we exit the program for a LOG(DFATAL) message in
  58. // debug mode. It does this by skipping the call to Fail/FailQuietly.
  59. // This is intended for testing only.
  60. //
  61. // This can have some effects on LOG(FATAL) as well. Failure messages
  62. // are always allocated (rather than sharing a buffer), the crash
  63. // reason is not recorded, the "gwq" status message is not updated,
  64. // and the stack trace is not recorded. The LOG(FATAL) *will* still
  65. // exit the program. Since this function is used only in testing,
  66. // these differences are acceptable.
  67. //
  68. // Additionally, LOG(LEVEL(FATAL)) is indistinguishable from LOG(DFATAL) and
  69. // will not terminate the program if SetExitOnDFatal(false) has been called.
  70. bool ExitOnDFatal();
  71. // SetExitOnDFatal() sets the ExitOnDFatal() status
  72. void SetExitOnDFatal(bool on_off);
  73. // Determines if the logging library should suppress logging of stacktraces in
  74. // the `SIGABRT` handler, typically because we just logged a stacktrace as part
  75. // of `LOG(FATAL)` and are about to send ourselves a `SIGABRT` to end the
  76. // program.
  77. bool SuppressSigabortTrace();
  78. // Sets the SuppressSigabortTrace() status and returns the previous state.
  79. bool SetSuppressSigabortTrace(bool on_off);
  80. } // namespace log_internal
  81. Y_ABSL_NAMESPACE_END
  82. } // namespace y_absl
  83. #endif // Y_ABSL_LOG_INTERNAL_GLOBALS_H_