OR-Tools  8.2
vlog_is_on.h
Go to the documentation of this file.
1 // Copyright 2010-2018 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 
19 
20 namespace google {
21 
22 #if defined(__GNUC__DISABLED)
23 // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
24 // (Normally) the first time every VLOG_IS_ON(n) site is hit,
25 // we determine what variable will dynamically control logging at this site:
26 // it's either absl::GetFlag(FLAGS_v) or an appropriate internal variable
27 // matching the current source file that represents results of
28 // parsing of --vmodule flag and/or SetVLOGLevel calls.
29 #define VLOG_IS_ON(verboselevel) \
30  __extension__({ \
31  static int32* vlocal__ = &google::kLogSiteUninitialized; \
32  int32 verbose_level__ = (verboselevel); \
33  (*vlocal__ >= verbose_level__) && \
34  ((vlocal__ != &google::kLogSiteUninitialized) || \
35  (google::InitVLOG3__(&vlocal__, &absl::GetFlag(FLAGS_v), __FILE__, \
36  verbose_level__))); \
37  })
38 #else
39 // GNU extensions not available, so we do not support --vmodule.
40 // Dynamic value of absl::GetFlag(FLAGS_v) always controls the logging level.
41 #define VLOG_IS_ON(verboselevel) (absl::GetFlag(FLAGS_v) >= (verboselevel))
42 #endif
43 
44 // Set VLOG(_IS_ON) level for module_pattern to log_level.
45 // This lets us dynamically control what is normally set by the --vmodule flag.
46 // Returns the level that previously applied to module_pattern.
47 // NOTE: To change the log level for VLOG(_IS_ON) sites
48 // that have already executed after/during InitGoogleLogging,
49 //. one needs to supply the exact --vmodule pattern that applied to them.
50 // (If no --vmodule pattern applied to them
51 // the value of FLAGS_v will continue to control them.)
52 extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern,
53  int log_level);
54 
55 // Various declarations needed for VLOG_IS_ON above: =========================
56 
57 // Special value used to indicate that a VLOG_IS_ON site has not been
58 // initialized. We make this a large value, so the common-case check
59 // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
60 // passes in such cases and InitVLOG3__ is then triggered.
62 
63 // Helper routine which determines the logging info for a particalur VLOG site.
64 // site_flag is the address of the site-local pointer to the controlling
65 // verbosity level
66 // site_default is the default to use for *site_flag
67 // fname is the current source file name
68 // verbose_level is the argument to VLOG_IS_ON
69 // We will return the return value for VLOG_IS_ON
70 // and if possible set *site_flag appropriately.
71 extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(int32** site_flag,
72  int32* site_default,
73  const char* fname,
74  int32 verbose_level);
75 
76 } // namespace google
77 
78 #endif // OR_TOOLS_BASE_VLOG_IS_ON_H_
int int32
#define GOOGLE_GLOG_DLL_DECL
bool InitVLOG3__(int32 **site_flag, int32 *site_default, const char *fname, int32 verbose_level)
Definition: vlog_is_on.cc:186
int32 kLogSiteUninitialized
Definition: vlog_is_on.cc:90
int SetVLOGLevel(const char *module_pattern, int log_level)
Definition: vlog_is_on.cc:151