Back to home page

EIC code displayed by LXR

 
 

    


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/absl_vlog_is_on.h
0017 // -----------------------------------------------------------------------------
0018 //
0019 // This header defines the `ABSL_VLOG_IS_ON()` macro that controls the
0020 // variable-verbosity conditional logging.
0021 //
0022 // It's used by `VLOG` in log.h, or it can also be used directly like this:
0023 //
0024 //   if (ABSL_VLOG_IS_ON(2)) {
0025 //     foo_server.RecomputeStatisticsExpensive();
0026 //     LOG(INFO) << foo_server.LastStatisticsAsString();
0027 //   }
0028 //
0029 // Each source file has an effective verbosity level that's a non-negative
0030 // integer computed from the `--vmodule` and `--v` flags.
0031 // `ABSL_VLOG_IS_ON(n)` is true, and `VLOG(n)` logs, if that effective verbosity
0032 // level is greater than or equal to `n`.
0033 //
0034 // `--vmodule` takes a comma-delimited list of key=value pairs.  Each key is a
0035 // pattern matched against filenames, and the values give the effective severity
0036 // level applied to matching files.  '?' and '*' characters in patterns are
0037 // interpreted as single-character and zero-or-more-character wildcards.
0038 // Patterns including a slash character are matched against full pathnames,
0039 // while those without are matched against basenames only.  One suffix (i.e. the
0040 // last . and everything after it) is stripped from each filename prior to
0041 // matching, as is the special suffix "-inl".
0042 //
0043 // Files are matched against globs in `--vmodule` in order, and the first match
0044 // determines the verbosity level.
0045 //
0046 // Files which do not match any pattern in `--vmodule` use the value of `--v` as
0047 // their effective verbosity level.  The default is 0.
0048 //
0049 // SetVLogLevel helper function is provided to do limited dynamic control over
0050 // V-logging by appending to `--vmodule`. Because these go at the beginning of
0051 // the list, they take priority over any globs previously added.
0052 //
0053 // Resetting --vmodule will override all previous modifications to `--vmodule`,
0054 // including via SetVLogLevel.
0055 
0056 #ifndef ABSL_LOG_ABSL_VLOG_IS_ON_H_
0057 #define ABSL_LOG_ABSL_VLOG_IS_ON_H_
0058 
0059 #include "absl/base/attributes.h"
0060 #include "absl/base/config.h"
0061 #include "absl/log/internal/vlog_config.h"  // IWYU pragma: export
0062 #include "absl/strings/string_view.h"
0063 
0064 // IWYU pragma: private, include "absl/log/log.h"
0065 
0066 // This is expanded at the callsite to allow the compiler to optimize
0067 // always-false cases out of the build.
0068 // An ABSL_MAX_VLOG_VERBOSITY of 2 means that VLOG(3) and above should never
0069 // log.
0070 #ifdef ABSL_MAX_VLOG_VERBOSITY
0071 #define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x) \
0072   ((x) <= ABSL_MAX_VLOG_VERBOSITY)&&
0073 #else
0074 #define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x)
0075 #endif
0076 
0077 // Each ABSL_VLOG_IS_ON call site gets its own VLogSite that registers with the
0078 // global linked list of sites to asynchronously update its verbosity level on
0079 // changes to --v or --vmodule. The verbosity can also be set by manually
0080 // calling SetVLogLevel.
0081 //
0082 // ABSL_VLOG_IS_ON is not async signal safe, but it is guaranteed not to
0083 // allocate new memory.
0084 #define ABSL_VLOG_IS_ON(verbose_level)                                     \
0085   (ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(verbose_level)[]()            \
0086        ->::absl::log_internal::VLogSite *                                  \
0087    {                                                                       \
0088      ABSL_CONST_INIT static ::absl::log_internal::VLogSite site(__FILE__); \
0089      return &site;                                                         \
0090    }()                                                                     \
0091        ->IsEnabled(verbose_level))
0092 
0093 #endif  // ABSL_LOG_ABSL_VLOG_IS_ON_H_