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