23 #include "absl/flags/flag.h"
24 #include "absl/synchronization/mutex.h"
27 "Show all VLOG(m) messages for m <= this."
28 " Overridable by --vmodule.");
31 "per-module verbose level."
32 " Argument is a comma-separated list of <module name>=<log level>."
33 " <module name> is a glob pattern, matched against the filename base"
34 " (that is, name ignoring .cc/.h./-inl.h)."
35 " <log level> overrides any value given by --v.");
39 namespace logging_internal {
42 bool SafeFNMatch_(
const char* pattern,
size_t patt_len,
const char* str,
49 bool SafeFNMatch_(
const char* pattern,
size_t patt_len,
const char* str,
54 if (p == patt_len && s == str_len)
return true;
55 if (p == patt_len)
return false;
56 if (s == str_len)
return p + 1 == patt_len && pattern[p] ==
'*';
57 if (pattern[p] == str[s] || pattern[p] ==
'?') {
62 if (pattern[p] ==
'*') {
63 if (p + 1 == patt_len)
return true;
65 if (
SafeFNMatch_(pattern + (p + 1), patt_len - (p + 1), str + s,
70 }
while (s != str_len);
112 const std::string vmodule_flag = absl::GetFlag(FLAGS_vmodule);
113 const char* vmodule = vmodule_flag.c_str();
117 while ((sep = strchr(vmodule,
'=')) !=
nullptr) {
118 std::string pattern(vmodule, sep - vmodule);
120 if (sscanf(sep,
"=%d", &module_level) == 1) {
131 vmodule = strchr(sep,
',');
132 if (vmodule ==
nullptr)
break;
144 int result = absl::GetFlag(FLAGS_v);
145 int const pattern_len = strlen(module_pattern);
151 if (info->module_pattern == module_pattern) {
153 result = info->vlog_level;
156 info->vlog_level = log_level;
157 }
else if (!found &&
SafeFNMatch_(info->module_pattern.c_str(),
158 info->module_pattern.size(),
159 module_pattern, pattern_len)) {
160 result = info->vlog_level;
178 bool InitVLOG3__(int32_t** vmodule_info,
bool* initialized,
const char* fname,
179 int32_t verbose_level) {
182 if (!read_vmodule_flag) {
188 int old_errno = errno;
194 const char* base = strrchr(fname,
'/');
195 base = base ? (base + 1) : fname;
196 const char* base_end = strchr(base,
'.');
197 size_t base_length = base_end ? size_t(base_end - base) : strlen(base);
200 if (base_length >= 4 && (memcmp(base + base_length - 4,
"-inl", 4) == 0)) {
211 if (
SafeFNMatch_(info->module_pattern.c_str(), info->module_pattern.size(),
212 base, base_length)) {
213 *vmodule_info = &info->vlog_level;
223 return *vmodule_info ==
nullptr ? absl::GetFlag(FLAGS_v) >= verbose_level
224 : **vmodule_info >= verbose_level;
bool SafeFNMatch_(const char *pattern, size_t patt_len, const char *str, size_t str_len)
int SetVLOGLevel(const char *module_pattern, int log_level)
int32_t kLogSiteUninitialized
static absl::Mutex vmodule_lock
static bool inited_vmodule
static VModuleInfo * vmodule_list
bool InitVLOG3__(int32_t **vmodule_info, bool *initialized, const char *fname, int32_t verbose_level)
static void VLOG2Initializer()
std::string module_pattern
ABSL_FLAG(int, v, 0, "Show all VLOG(m) messages for m <= this." " Overridable by --vmodule.")