Initial windows support. Now we don't have the stacktrace and several unittests.
[platform/upstream/glog.git] / src / glog / vlog_is_on.h.in
1 // Copyright 1999, 2007 Google Inc. All Rights Reserved.
2 // Author: Ray Sidney and many others
3 //
4 // Defines the VLOG_IS_ON macro that controls the variable-verbosity
5 // conditional logging.
6 //
7 // It's used by VLOG and VLOG_IF in logging.h
8 // and by RAW_VLOG in raw_logging.h to trigger the logging.
9 //
10 // It can also be used directly e.g. like this:
11 //   if (VLOG_IS_ON(2)) {
12 //     // do some logging preparation and logging
13 //     // that can't be accomplished e.g. via just VLOG(2) << ...;
14 //   }
15 //
16 // The truth value that VLOG_IS_ON(level) returns is determined by 
17 // the three verbosity level flags:
18 //   --v=<n>  Gives the default maximal active V-logging level;
19 //            0 is the default.
20 //            Normally positive values are used for V-logging levels.
21 //   --vmodule=<str>  Gives the per-module maximal V-logging levels to override
22 //                    the value given by --v.
23 //                    E.g. "my_module=2,foo*=3" would change the logging level
24 //                    for all code in source files "my_module.*" and "foo*.*"
25 //                    ("-inl" suffixes are also disregarded for this matching).
26 //
27 // SetVLOGLevel helper function is provided to do limited dynamic control over
28 // V-logging by overriding the per-module settings given via --vmodule flag.
29 //
30 // CAVEAT: --vmodule functionality is not available in non gcc compilers.
31 //
32
33 #ifndef BASE_VLOG_IS_ON_H_
34 #define BASE_VLOG_IS_ON_H_
35
36 #include "glog/log_severity.h"
37
38 // Annoying stuff for windows -- makes sure clients can import these functions
39 #ifndef GOOGLE_GLOG_DLL_DECL
40 # ifdef _WIN32
41 #   define GOOGLE_GLOG_DLL_DECL  __declspec(dllimport)
42 # else
43 #   define GOOGLE_GLOG_DLL_DECL
44 # endif
45 #endif
46
47 #if defined(__GNUC__)
48 // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
49 // (Normally) the first time every VLOG_IS_ON(n) site is hit,
50 // we determine what variable will dynamically control logging at this site:
51 // it's either FLAGS_v or an appropriate internal variable
52 // matching the current source file that represents results of
53 // parsing of --vmodule flag and/or SetVLOGLevel calls.
54 #define VLOG_IS_ON(verboselevel)                                \
55   ({ static @ac_google_namespace@::int32* vlocal__ = &@ac_google_namespace@::kLogSiteUninitialized;           \
56      @ac_google_namespace@::int32 verbose_level__ = (verboselevel);                    \
57      (*vlocal__ >= verbose_level__) &&                          \
58      ((vlocal__ != &@ac_google_namespace@::kLogSiteUninitialized) ||                   \
59       (@ac_google_namespace@::InitVLOG3__(&vlocal__, &FLAGS_v,                         \
60                    __FILE__, verbose_level__))); })
61 #else
62 // GNU extensions not available, so we do not support --vmodule.
63 // Dynamic value of FLAGS_v always controls the logging level.
64 #define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
65 #endif
66
67 // Set VLOG(_IS_ON) level for module_pattern to log_level.
68 // This lets us dynamically control what is normally set by the --vmodule flag.
69 // Returns the level that previously applied to module_pattern.
70 // NOTE: To change the log level for VLOG(_IS_ON) sites
71 //       that have already executed after/during InitGoogleLogging,
72 //       one needs to supply the exact --vmodule pattern that applied to them.
73 //       (If no --vmodule pattern applied to them
74 //       the value of FLAGS_v will continue to control them.)
75 extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern,
76                                              int log_level);
77
78 // Various declarations needed for VLOG_IS_ON above: =========================
79
80 // Special value used to indicate that a VLOG_IS_ON site has not been
81 // initialized.  We make this a large value, so the common-case check
82 // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition
83 // passes in such cases and InitVLOG3__ is then triggered.
84 extern @ac_google_namespace@::int32 kLogSiteUninitialized;
85
86 // Helper routine which determines the logging info for a particalur VLOG site.
87 //   site_flag     is the address of the site-local pointer to the controlling
88 //                 verbosity level
89 //   site_default  is the default to use for *site_flag
90 //   fname         is the current source file name
91 //   verbose_level is the argument to VLOG_IS_ON
92 // We will return the return value for VLOG_IS_ON
93 // and if possible set *site_flag appropriately.
94 extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__(
95     @ac_google_namespace@::int32** site_flag,
96     @ac_google_namespace@::int32* site_default,
97     const char* fname,
98     @ac_google_namespace@::int32 verbose_level);
99
100 #endif  // BASE_VLOG_IS_ON_H_