xref: /aosp_15_r20/external/abseil-cpp/absl/log/vlog_is_on.h (revision 9356374a3709195abf420251b3e825997ff56c0f)
1*9356374aSAndroid Build Coastguard Worker // Copyright 2022 The Abseil Authors.
2*9356374aSAndroid Build Coastguard Worker //
3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*9356374aSAndroid Build Coastguard Worker //
7*9356374aSAndroid Build Coastguard Worker //      https://www.apache.org/licenses/LICENSE-2.0
8*9356374aSAndroid Build Coastguard Worker //
9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*9356374aSAndroid Build Coastguard Worker // limitations under the License.
14*9356374aSAndroid Build Coastguard Worker //
15*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
16*9356374aSAndroid Build Coastguard Worker // File: log/vlog_is_on.h
17*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
18*9356374aSAndroid Build Coastguard Worker //
19*9356374aSAndroid Build Coastguard Worker // This header defines the `VLOG_IS_ON()` macro that controls the
20*9356374aSAndroid Build Coastguard Worker // variable-verbosity conditional logging.
21*9356374aSAndroid Build Coastguard Worker //
22*9356374aSAndroid Build Coastguard Worker // It's used by `VLOG` in log.h, or it can also be used directly like this:
23*9356374aSAndroid Build Coastguard Worker //
24*9356374aSAndroid Build Coastguard Worker //   if (VLOG_IS_ON(2)) {
25*9356374aSAndroid Build Coastguard Worker //     foo_server.RecomputeStatisticsExpensive();
26*9356374aSAndroid Build Coastguard Worker //     LOG(INFO) << foo_server.LastStatisticsAsString();
27*9356374aSAndroid Build Coastguard Worker //   }
28*9356374aSAndroid Build Coastguard Worker //
29*9356374aSAndroid Build Coastguard Worker // Each source file has an effective verbosity level that's a non-negative
30*9356374aSAndroid Build Coastguard Worker // integer computed from the `--vmodule` and `--v` flags.
31*9356374aSAndroid Build Coastguard Worker // `VLOG_IS_ON(n)` is true, and `VLOG(n)` logs, if that effective verbosity
32*9356374aSAndroid Build Coastguard Worker // level is greater than or equal to `n`.
33*9356374aSAndroid Build Coastguard Worker //
34*9356374aSAndroid Build Coastguard Worker // `--vmodule` takes a comma-delimited list of key=value pairs.  Each key is a
35*9356374aSAndroid Build Coastguard Worker // pattern matched against filenames, and the values give the effective severity
36*9356374aSAndroid Build Coastguard Worker // level applied to matching files.  '?' and '*' characters in patterns are
37*9356374aSAndroid Build Coastguard Worker // interpreted as single-character and zero-or-more-character wildcards.
38*9356374aSAndroid Build Coastguard Worker // Patterns including a slash character are matched against full pathnames,
39*9356374aSAndroid Build Coastguard Worker // while those without are matched against basenames only.  One suffix (i.e. the
40*9356374aSAndroid Build Coastguard Worker // last . and everything after it) is stripped from each filename prior to
41*9356374aSAndroid Build Coastguard Worker // matching, as is the special suffix "-inl".
42*9356374aSAndroid Build Coastguard Worker //
43*9356374aSAndroid Build Coastguard Worker // Files are matched against globs in `--vmodule` in order, and the first match
44*9356374aSAndroid Build Coastguard Worker // determines the verbosity level.
45*9356374aSAndroid Build Coastguard Worker //
46*9356374aSAndroid Build Coastguard Worker // Files which do not match any pattern in `--vmodule` use the value of `--v` as
47*9356374aSAndroid Build Coastguard Worker // their effective verbosity level.  The default is 0.
48*9356374aSAndroid Build Coastguard Worker //
49*9356374aSAndroid Build Coastguard Worker // SetVLogLevel helper function is provided to do limited dynamic control over
50*9356374aSAndroid Build Coastguard Worker // V-logging by appending to `--vmodule`. Because these go at the beginning of
51*9356374aSAndroid Build Coastguard Worker // the list, they take priority over any globs previously added.
52*9356374aSAndroid Build Coastguard Worker //
53*9356374aSAndroid Build Coastguard Worker // Resetting --vmodule will override all previous modifications to `--vmodule`,
54*9356374aSAndroid Build Coastguard Worker // including via SetVLogLevel.
55*9356374aSAndroid Build Coastguard Worker 
56*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_LOG_VLOG_IS_ON_H_
57*9356374aSAndroid Build Coastguard Worker #define ABSL_LOG_VLOG_IS_ON_H_
58*9356374aSAndroid Build Coastguard Worker 
59*9356374aSAndroid Build Coastguard Worker #include "absl/log/absl_vlog_is_on.h"  // IWYU pragma: export
60*9356374aSAndroid Build Coastguard Worker 
61*9356374aSAndroid Build Coastguard Worker // IWYU pragma: private, include "absl/log/log.h"
62*9356374aSAndroid Build Coastguard Worker 
63*9356374aSAndroid Build Coastguard Worker // Each VLOG_IS_ON call site gets its own VLogSite that registers with the
64*9356374aSAndroid Build Coastguard Worker // global linked list of sites to asynchronously update its verbosity level on
65*9356374aSAndroid Build Coastguard Worker // changes to --v or --vmodule. The verbosity can also be set by manually
66*9356374aSAndroid Build Coastguard Worker // calling SetVLogLevel.
67*9356374aSAndroid Build Coastguard Worker //
68*9356374aSAndroid Build Coastguard Worker // VLOG_IS_ON is not async signal safe, but it is guaranteed not to allocate
69*9356374aSAndroid Build Coastguard Worker // new memory.
70*9356374aSAndroid Build Coastguard Worker #define VLOG_IS_ON(verbose_level) ABSL_VLOG_IS_ON(verbose_level)
71*9356374aSAndroid Build Coastguard Worker 
72*9356374aSAndroid Build Coastguard Worker #endif  // ABSL_LOG_VLOG_IS_ON_H_
73