diff options
Diffstat (limited to 'base/vlog.h')
| -rw-r--r-- | base/vlog.h | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/base/vlog.h b/base/vlog.h index d4cffe4..529afd5 100644 --- a/base/vlog.h +++ b/base/vlog.h @@ -8,7 +8,6 @@ #include <cstddef> #include <string> -#include <utility> #include <vector> #include "base/basictypes.h" @@ -28,25 +27,63 @@ class VlogInfo { // E.g. "my_module=2,foo*=3" would change the logging level for all // code in source files "my_module.*" and "foo*.*" ("-inl" suffixes // are also disregarded for this matching). + // + // |log_severity| points to an int that stores the log level. If a valid + // |v_switch| is provided, it will set the log level, and the default + // vlog severity will be read from there.. + // + // Any pattern containing a forward or backward slash will be tested + // against the whole pathname and not just the module. E.g., + // "*/foo/bar/*=2" would change the logging level for all code in + // source files under a "foo/bar" directory. VlogInfo(const std::string& v_switch, - const std::string& vmodule_switch); + const std::string& vmodule_switch, + int* min_log_level); ~VlogInfo(); // Returns the vlog level for a given file (usually taken from // __FILE__). - int GetVlogLevel(const base::StringPiece& file); + int GetVlogLevel(const base::StringPiece& file) const; static const int kDefaultVlogLevel; private: - typedef std::pair<std::string, int> VmodulePattern; + void SetMaxVlogLevel(int level); + int GetMaxVlogLevel() const; + + // VmodulePattern holds all the information for each pattern parsed + // from |vmodule_switch|. + struct VmodulePattern { + enum MatchTarget { MATCH_MODULE, MATCH_FILE }; + + explicit VmodulePattern(const std::string& pattern); + + VmodulePattern(); + + std::string pattern; + int vlog_level; + MatchTarget match_target; + }; - int max_vlog_level_; std::vector<VmodulePattern> vmodule_levels_; + int* min_log_level_; DISALLOW_COPY_AND_ASSIGN(VlogInfo); }; +// Returns true if the string passed in matches the vlog pattern. The +// vlog pattern string can contain wildcards like * and ?. ? matches +// exactly one character while * matches 0 or more characters. Also, +// as a special case, a / or \ character matches either / or \. +// +// Examples: +// "kh?n" matches "khan" but not "khn" or "khaan" +// "kh*n" matches "khn", "khan", or even "khaaaaan" +// "/foo\bar" matches "/foo/bar", "\foo\bar", or "/foo\bar" +// (disregarding C escaping rules) +bool MatchVlogPattern(const base::StringPiece& string, + const base::StringPiece& vlog_pattern); + } // namespace logging #endif // BASE_VLOG_H_ |
