1 // This file is automatically generated from src/glog/vlog_is_on.h.in
2 // using src/windows/preprocess.sh.
5 // Copyright (c) 1999, 2007, Google Inc.
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
18 // * Neither the name of Google Inc. nor the names of its
19 // contributors may be used to endorse or promote products derived from
20 // this software without specific prior written permission.
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // Author: Ray Sidney and many others
36 // Defines the VLOG_IS_ON macro that controls the variable-verbosity
37 // conditional logging.
39 // It's used by VLOG and VLOG_IF in logging.h
40 // and by RAW_VLOG in raw_logging.h to trigger the logging.
42 // It can also be used directly e.g. like this:
43 // if (VLOG_IS_ON(2)) {
44 // // do some logging preparation and logging
45 // // that can't be accomplished e.g. via just VLOG(2) << ...;
48 // The truth value that VLOG_IS_ON(level) returns is determined by
49 // the three verbosity level flags:
50 // --v=<n> Gives the default maximal active V-logging level;
52 // Normally positive values are used for V-logging levels.
53 // --vmodule=<str> Gives the per-module maximal V-logging levels to override
54 // the value given by --v.
55 // E.g. "my_module=2,foo*=3" would change the logging level
56 // for all code in source files "my_module.*" and "foo*.*"
57 // ("-inl" suffixes are also disregarded for this matching).
59 // SetVLOGLevel helper function is provided to do limited dynamic control over
60 // V-logging by overriding the per-module settings given via --vmodule flag.
62 // CAVEAT: --vmodule functionality is not available in non gcc compilers.
65 #ifndef BASE_VLOG_IS_ON_H_
66 #define BASE_VLOG_IS_ON_H_
68 #include "glog/log_severity.h"
70 // Annoying stuff for windows -- makes sure clients can import these functions
71 #ifndef GOOGLE_GLOG_DLL_DECL
72 # if defined(_WIN32) && !defined(__CYGWIN__)
73 # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport)
75 # define GOOGLE_GLOG_DLL_DECL
80 // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
81 // (Normally) the first time every VLOG_IS_ON(n) site is hit,
82 // we determine what variable will dynamically control logging at this site:
83 // it's either FLAGS_v or an appropriate internal variable
84 // matching the current source file that represents results of
85 // parsing of --vmodule flag and/or SetVLOGLevel calls.
86 #define VLOG_IS_ON(verboselevel) \
87 ({ static google::int32* vlocal__ = &google::kLogSiteUninitialized; \
88 google::int32 verbose_level__ = (verboselevel); \
89 (*vlocal__ >= verbose_level__) && \
90 ((vlocal__ != &google::kLogSiteUninitialized) || \
91 (google::InitVLOG3__(&vlocal__, &FLAGS_v, \
92 __FILE__, verbose_level__))); })
94 // GNU extensions not available, so we do not support --vmodule.
95 // Dynamic value of FLAGS_v always controls the logging level.
96 #define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
99 // Set VLOG(_IS_ON) level for module_pattern to log_level.
100 // This lets us dynamically control what is normally set by the --vmodule flag.
101 // Returns the level that previously applied to module_pattern.
102 // NOTE: To change the log level for VLOG(_IS_ON) sites
103 // that have already executed after/during InitGoogleLogging,
104 // one needs to supply the exact --vmodule pattern that applied to them.
105 // (If no --vmodule pattern applied to them
106 // the value of FLAGS_v will continue to control them.)
107 extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern,
110 // Various declarations needed for VLOG_IS_ON above: =========================
112 // Special value used to indicate that a VLOG_IS_ON site has not been
113 // initialized. We make this a large value, so the common-case check
114 // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
115 // passes in such cases and InitVLOG3__ is then triggered.
116 extern google::int32 kLogSiteUninitialized;
118 // Helper routine which determines the logging info for a particalur VLOG site.
119 // site_flag is the address of the site-local pointer to the controlling
121 // site_default is the default to use for *site_flag
122 // fname is the current source file name
123 // verbose_level is the argument to VLOG_IS_ON
124 // We will return the return value for VLOG_IS_ON
125 // and if possible set *site_flag appropriately.
126 extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(
127 google::int32** site_flag,
128 google::int32* site_default,
130 google::int32 verbose_level);
132 #endif // BASE_VLOG_IS_ON_H_