OR-Tools  9.3
vlog_is_on.h
Go to the documentation of this file.
1// Copyright 2010-2021 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
20namespace google {
21
22#if defined(__GNUC__)
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 bool vmodule_initialized__ = false; \
32 static int32_t* vmodule_info__ = nullptr; \
33 int32_t verbose_level__ = (verboselevel); \
34 (vmodule_initialized__ \
35 ? (vmodule_info__ == nullptr \
36 ? absl::GetFlag(FLAGS_v) >= verbose_level__ \
37 : *vmodule_info__ >= verbose_level__) \
38 : google::InitVLOG3__(&vmodule_info__, &vmodule_initialized__, \
39 __FILE__, verbose_level__)); \
40 })
41#else
42// GNU extensions not available, so we do not support --vmodule.
43// Dynamic value of absl::GetFlag(FLAGS_v) always controls the logging level.
44#define VLOG_IS_ON(verboselevel) (absl::GetFlag(FLAGS_v) >= (verboselevel))
45#endif
46
47// Set VLOG(_IS_ON) level for module_pattern to log_level.
48// This lets us dynamically control what is normally set by the --vmodule flag.
49// Returns the level that previously applied to module_pattern.
50// NOTE: To change the log level for VLOG(_IS_ON) sites
51// that have already executed after/during InitGoogleLogging,
52//. one needs to supply the exact --vmodule pattern that applied to them.
53// (If no --vmodule pattern applied to them
54// the value of FLAGS_v will continue to control them.)
55extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern,
56 int log_level);
57
58// Various declarations needed for VLOG_IS_ON above: =========================
59
60// Special value used to indicate that a VLOG_IS_ON site has not been
61// initialized. We make this a large value, so the common-case check
62// of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
63// passes in such cases and InitVLOG3__ is then triggered.
64extern int32_t kLogSiteUninitialized;
65
66// Helper routine which determines the logging info for a particalur VLOG site.
67// get_level is a function that returns the log level
68// initialized is a boolean value that tells if vmodule was initialized
69// for that file.
70// fname is the current source file name
71// verbose_level is the argument to VLOG_IS_ON
72// We will return the return value for VLOG_IS_ON
73// and if possible set *site_flag appropriately.
74extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(int32_t** vmodule_info,
75 bool* initialized,
76 const char* fname,
77 int32_t verbose_level);
78
79} // namespace google
80
81#endif // OR_TOOLS_BASE_VLOG_IS_ON_H_
#define GOOGLE_GLOG_DLL_DECL
int32_t kLogSiteUninitialized
Definition: vlog_is_on.cc:85
int SetVLOGLevel(const char *module_pattern, int log_level)
Definition: vlog_is_on.cc:147
bool InitVLOG3__(int32_t **vmodule_info, bool *initialized, const char *fname, int32_t verbose_level)
Definition: vlog_is_on.cc:182