|
|
|||
File indexing completed on 2025-12-16 09:40:53
0001 // Copyright 2022 The Abseil Authors. 0002 // 0003 // Licensed under the Apache License, Version 2.0 (the "License"); 0004 // you may not use this file except in compliance with the License. 0005 // You may obtain a copy of the License at 0006 // 0007 // https://www.apache.org/licenses/LICENSE-2.0 0008 // 0009 // Unless required by applicable law or agreed to in writing, software 0010 // distributed under the License is distributed on an "AS IS" BASIS, 0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0012 // See the License for the specific language governing permissions and 0013 // limitations under the License. 0014 // 0015 // ----------------------------------------------------------------------------- 0016 // File: log/globals.h 0017 // ----------------------------------------------------------------------------- 0018 // 0019 // This header declares global logging library configuration knobs. 0020 0021 #ifndef ABSL_LOG_GLOBALS_H_ 0022 #define ABSL_LOG_GLOBALS_H_ 0023 0024 #include "absl/base/attributes.h" 0025 #include "absl/base/config.h" 0026 #include "absl/base/log_severity.h" 0027 #include "absl/log/internal/vlog_config.h" 0028 #include "absl/strings/string_view.h" 0029 0030 namespace absl { 0031 ABSL_NAMESPACE_BEGIN 0032 0033 //------------------------------------------------------------------------------ 0034 // Minimum Log Level 0035 //------------------------------------------------------------------------------ 0036 // 0037 // Messages logged at or above this severity are directed to all registered log 0038 // sinks or skipped otherwise. This parameter can also be modified using 0039 // command line flag --minloglevel. 0040 // See absl/base/log_severity.h for descriptions of severity levels. 0041 0042 // MinLogLevel() 0043 // 0044 // Returns the value of the Minimum Log Level parameter. 0045 // This function is async-signal-safe. 0046 ABSL_MUST_USE_RESULT absl::LogSeverityAtLeast MinLogLevel(); 0047 0048 // SetMinLogLevel() 0049 // 0050 // Updates the value of Minimum Log Level parameter. 0051 // This function is async-signal-safe. 0052 void SetMinLogLevel(absl::LogSeverityAtLeast severity); 0053 0054 namespace log_internal { 0055 0056 // ScopedMinLogLevel 0057 // 0058 // RAII type used to temporarily update the Min Log Level parameter. 0059 class ScopedMinLogLevel final { 0060 public: 0061 explicit ScopedMinLogLevel(absl::LogSeverityAtLeast severity); 0062 ScopedMinLogLevel(const ScopedMinLogLevel&) = delete; 0063 ScopedMinLogLevel& operator=(const ScopedMinLogLevel&) = delete; 0064 ~ScopedMinLogLevel(); 0065 0066 private: 0067 absl::LogSeverityAtLeast saved_severity_; 0068 }; 0069 0070 } // namespace log_internal 0071 0072 //------------------------------------------------------------------------------ 0073 // Stderr Threshold 0074 //------------------------------------------------------------------------------ 0075 // 0076 // Messages logged at or above this level are directed to stderr in 0077 // addition to other registered log sinks. This parameter can also be modified 0078 // using command line flag --stderrthreshold. 0079 // See absl/base/log_severity.h for descriptions of severity levels. 0080 0081 // StderrThreshold() 0082 // 0083 // Returns the value of the Stderr Threshold parameter. 0084 // This function is async-signal-safe. 0085 ABSL_MUST_USE_RESULT absl::LogSeverityAtLeast StderrThreshold(); 0086 0087 // SetStderrThreshold() 0088 // 0089 // Updates the Stderr Threshold parameter. 0090 // This function is async-signal-safe. 0091 void SetStderrThreshold(absl::LogSeverityAtLeast severity); 0092 inline void SetStderrThreshold(absl::LogSeverity severity) { 0093 absl::SetStderrThreshold(static_cast<absl::LogSeverityAtLeast>(severity)); 0094 } 0095 0096 // ScopedStderrThreshold 0097 // 0098 // RAII type used to temporarily update the Stderr Threshold parameter. 0099 class ScopedStderrThreshold final { 0100 public: 0101 explicit ScopedStderrThreshold(absl::LogSeverityAtLeast severity); 0102 ScopedStderrThreshold(const ScopedStderrThreshold&) = delete; 0103 ScopedStderrThreshold& operator=(const ScopedStderrThreshold&) = delete; 0104 ~ScopedStderrThreshold(); 0105 0106 private: 0107 absl::LogSeverityAtLeast saved_severity_; 0108 }; 0109 0110 //------------------------------------------------------------------------------ 0111 // Log Backtrace At 0112 //------------------------------------------------------------------------------ 0113 // 0114 // Users can request an existing `LOG` statement, specified by file and line 0115 // number, to also include a backtrace when logged. 0116 0117 // ShouldLogBacktraceAt() 0118 // 0119 // Returns true if we should log a backtrace at the specified location. 0120 namespace log_internal { 0121 ABSL_MUST_USE_RESULT bool ShouldLogBacktraceAt(absl::string_view file, 0122 int line); 0123 } // namespace log_internal 0124 0125 // SetLogBacktraceLocation() 0126 // 0127 // Sets the location the backtrace should be logged at. If the specified 0128 // location isn't a `LOG` statement, the effect will be the same as 0129 // `ClearLogBacktraceLocation` (but less efficient). 0130 void SetLogBacktraceLocation(absl::string_view file, int line); 0131 0132 // ClearLogBacktraceLocation() 0133 // 0134 // Clears the set location so that backtraces will no longer be logged at it. 0135 void ClearLogBacktraceLocation(); 0136 0137 //------------------------------------------------------------------------------ 0138 // Prepend Log Prefix 0139 //------------------------------------------------------------------------------ 0140 // 0141 // This option tells the logging library that every logged message 0142 // should include the prefix (severity, date, time, PID, etc.) 0143 // 0144 // ShouldPrependLogPrefix() 0145 // 0146 // Returns the value of the Prepend Log Prefix option. 0147 // This function is async-signal-safe. 0148 ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix(); 0149 0150 // EnableLogPrefix() 0151 // 0152 // Updates the value of the Prepend Log Prefix option. 0153 // This function is async-signal-safe. 0154 void EnableLogPrefix(bool on_off); 0155 0156 //------------------------------------------------------------------------------ 0157 // `VLOG` Configuration 0158 //------------------------------------------------------------------------------ 0159 // 0160 // These methods set the `(ABSL_)VLOG(_IS_ON)` threshold. They allow 0161 // programmatic control of the thresholds set by the --v and --vmodule flags. 0162 // 0163 // Only `VLOG`s with a severity level LESS THAN OR EQUAL TO the threshold will 0164 // be evaluated. 0165 // 0166 // For example, if the threshold is 2, then: 0167 // 0168 // VLOG(2) << "This message will be logged."; 0169 // VLOG(3) << "This message will NOT be logged."; 0170 // 0171 // The default threshold is 0. Since `VLOG` levels must not be negative, a 0172 // negative threshold value will turn off all VLOGs. 0173 0174 // SetGlobalVLogLevel() 0175 // 0176 // Sets the global `VLOG` level to threshold. Returns the previous global 0177 // threshold. 0178 inline int SetGlobalVLogLevel(int threshold) { 0179 return absl::log_internal::UpdateGlobalVLogLevel(threshold); 0180 } 0181 0182 // SetVLogLevel() 0183 // 0184 // Sets the `VLOG` threshold for all files that match `module_pattern`, 0185 // overwriting any prior value. Files that don't match aren't affected. 0186 // Returns the threshold that previously applied to `module_pattern`. 0187 inline int SetVLogLevel(absl::string_view module_pattern, int threshold) { 0188 return absl::log_internal::PrependVModule(module_pattern, threshold); 0189 } 0190 0191 //------------------------------------------------------------------------------ 0192 // Configure Android Native Log Tag 0193 //------------------------------------------------------------------------------ 0194 // 0195 // The logging library forwards to the Android system log API when built for 0196 // Android. That API takes a string "tag" value in addition to a message and 0197 // severity level. The tag is used to identify the source of messages and to 0198 // filter them. This library uses the tag "native" by default. 0199 0200 // SetAndroidNativeTag() 0201 // 0202 // Stores a copy of the string pointed to by `tag` and uses it as the Android 0203 // logging tag thereafter. `tag` must not be null. 0204 // This function must not be called more than once! 0205 void SetAndroidNativeTag(const char* tag); 0206 0207 namespace log_internal { 0208 // GetAndroidNativeTag() 0209 // 0210 // Returns the configured Android logging tag. 0211 const char* GetAndroidNativeTag(); 0212 } // namespace log_internal 0213 0214 namespace log_internal { 0215 0216 using LoggingGlobalsListener = void (*)(); 0217 void SetLoggingGlobalsListener(LoggingGlobalsListener l); 0218 0219 // Internal implementation for the setter routines. These are used 0220 // to break circular dependencies between flags and globals. Each "Raw" 0221 // routine corresponds to the non-"Raw" counterpart and used to set the 0222 // configuration parameter directly without calling back to the listener. 0223 void RawSetMinLogLevel(absl::LogSeverityAtLeast severity); 0224 void RawSetStderrThreshold(absl::LogSeverityAtLeast severity); 0225 void RawEnableLogPrefix(bool on_off); 0226 0227 } // namespace log_internal 0228 ABSL_NAMESPACE_END 0229 } // namespace absl 0230 0231 #endif // ABSL_LOG_GLOBALS_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|