OR-Tools  9.6
vlog_is_on.h
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_BASE_VLOG_IS_ON_H_
15 #define OR_TOOLS_BASE_VLOG_IS_ON_H_
16 
17 #include "absl/flags/declare.h"
18 #include "absl/log/log.h"
20 
22 
23 namespace google {
24 
25 #if defined(__GNUC__)
26 // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
27 // (Normally) the first time every VLOG_IS_ON(n) site is hit,
28 // we determine what variable will dynamically control logging at this site:
29 // it's either absl::GetFlag(FLAGS_v) or an appropriate internal variable
30 // matching the current source file that represents results of
31 // parsing of --vmodule flag and/or SetVLOGLevel calls.
32 #define VLOG_IS_ON(verboselevel) \
33  __extension__({ \
34  static bool vmodule_initialized__ = false; \
35  static int32_t* vmodule_info__ = nullptr; \
36  int32_t verbose_level__ = (verboselevel); \
37  (vmodule_initialized__ \
38  ? (vmodule_info__ == nullptr \
39  ? absl::GetFlag(FLAGS_v) >= verbose_level__ \
40  : *vmodule_info__ >= verbose_level__) \
41  : google::InitVLOG3__(&vmodule_info__, &vmodule_initialized__, \
42  __FILE__, verbose_level__)); \
43  })
44 #else
45 // GNU extensions not available, so we do not support --vmodule.
46 // Dynamic value of absl::GetFlag(FLAGS_v) always controls the logging level.
47 #define VLOG_IS_ON(verboselevel) (absl::GetFlag(FLAGS_v) >= (verboselevel))
48 #endif
49 
50 // Set VLOG(_IS_ON) level for module_pattern to log_level.
51 // This lets us dynamically control what is normally set by the --vmodule flag.
52 // Returns the level that previously applied to module_pattern.
53 // NOTE: To change the log level for VLOG(_IS_ON) sites
54 // that have already executed after/during InitGoogleLogging,
55 //. one needs to supply the exact --vmodule pattern that applied to them.
56 // (If no --vmodule pattern applied to them
57 // the value of FLAGS_v will continue to control them.)
58 extern int SetVLOGLevel(const char* module_pattern, int log_level);
59 
60 // Various declarations needed for VLOG_IS_ON above: =========================
61 
62 // Special value used to indicate that a VLOG_IS_ON site has not been
63 // initialized. We make this a large value, so the common-case check
64 // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
65 // passes in such cases and InitVLOG3__ is then triggered.
66 extern int32_t kLogSiteUninitialized;
67 
68 // Helper routine which determines the logging info for a particalur VLOG site.
69 // get_level is a function that returns the log level
70 // initialized is a boolean value that tells if vmodule was initialized
71 // for that file.
72 // fname is the current source file name
73 // verbose_level is the argument to VLOG_IS_ON
74 // We will return the return value for VLOG_IS_ON
75 // and if possible set *site_flag appropriately.
76 extern bool InitVLOG3__(int32_t** vmodule_info, bool* initialized,
77  const char* fname, int32_t verbose_level);
78 
79 } // namespace google
80 
81 #endif // OR_TOOLS_BASE_VLOG_IS_ON_H_
int SetVLOGLevel(const char *module_pattern, int log_level)
Definition: vlog_is_on.cc:143
int32_t kLogSiteUninitialized
Definition: vlog_is_on.cc:81
bool InitVLOG3__(int32_t **vmodule_info, bool *initialized, const char *fname, int32_t verbose_level)
Definition: vlog_is_on.cc:178
ABSL_DECLARE_FLAG(int, v)