23#include "absl/synchronization/mutex.h"
31 "Show all VLOG(m) messages for m <= this."
32 " Overridable by --vmodule.");
35 "per-module verbose level."
36 " Argument is a comma-separated list of <module name>=<log level>."
37 " <module name> is a glob pattern, matched against the filename base"
38 " (that is, name ignoring .cc/.h./-inl.h)."
39 " <log level> overrides any value given by --v.");
43namespace logging_internal {
47 const char* str,
size_t str_len);
54 const char* str,
size_t str_len) {
58 if (p == patt_len && s == str_len)
return true;
59 if (p == patt_len)
return false;
60 if (s == str_len)
return p + 1 == patt_len && pattern[p] ==
'*';
61 if (pattern[p] == str[s] || pattern[p] ==
'?') {
66 if (pattern[p] ==
'*') {
67 if (p + 1 == patt_len)
return true;
69 if (
SafeFNMatch_(pattern + (p + 1), patt_len - (p + 1), str + s,
74 }
while (s != str_len);
116 const std::string vmodule_flag = absl::GetFlag(FLAGS_vmodule);
117 const char* vmodule = vmodule_flag.c_str();
121 while ((sep = strchr(vmodule,
'=')) !=
nullptr) {
122 std::string pattern(vmodule, sep - vmodule);
124 if (sscanf(sep,
"=%d", &module_level) == 1) {
135 vmodule = strchr(sep,
',');
136 if (vmodule ==
nullptr)
break;
148 int result = absl::GetFlag(FLAGS_v);
149 int const pattern_len = strlen(module_pattern);
155 if (info->module_pattern == module_pattern) {
157 result = info->vlog_level;
160 info->vlog_level = log_level;
161 }
else if (!found &&
SafeFNMatch_(info->module_pattern.c_str(),
162 info->module_pattern.size(),
163 module_pattern, pattern_len)) {
164 result = info->vlog_level;
176 RAW_VLOG(1,
"Set VLOG level for \"%s\" to %d", module_pattern, log_level);
182bool InitVLOG3__(int32_t** vmodule_info,
bool* initialized,
const char* fname,
183 int32_t verbose_level) {
186 if (!read_vmodule_flag) {
192 int old_errno = errno;
198 const char* base = strrchr(fname,
'/');
199 base = base ? (base + 1) : fname;
200 const char* base_end = strchr(base,
'.');
201 size_t base_length = base_end ? size_t(base_end - base) : strlen(base);
204 if (base_length >= 4 && (memcmp(base + base_length - 4,
"-inl", 4) == 0)) {
215 if (
SafeFNMatch_(info->module_pattern.c_str(), info->module_pattern.size(),
216 base, base_length)) {
217 *vmodule_info = &info->vlog_level;
227 return *vmodule_info ==
nullptr ? absl::GetFlag(FLAGS_v) >= verbose_level
228 : **vmodule_info >= verbose_level;
#define GOOGLE_GLOG_DLL_DECL
GOOGLE_GLOG_DLL_DECL bool SafeFNMatch_(const char *pattern, size_t patt_len, const char *str, size_t str_len)
int32_t kLogSiteUninitialized
static absl::Mutex vmodule_lock
static bool inited_vmodule
static VModuleInfo * vmodule_list
static void VLOG2Initializer()
int SetVLOGLevel(const char *module_pattern, int log_level)
bool InitVLOG3__(int32_t **vmodule_info, bool *initialized, const char *fname, int32_t verbose_level)
#define RAW_VLOG(verboselevel,...)
std::string module_pattern
ABSL_FLAG(int, v, 0, "Show all VLOG(m) messages for m <= this." " Overridable by --vmodule.")