1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_VLOG_H_ 6*635a8641SAndroid Build Coastguard Worker #define BASE_VLOG_H_ 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker #include <string> 9*635a8641SAndroid Build Coastguard Worker #include <vector> 10*635a8641SAndroid Build Coastguard Worker 11*635a8641SAndroid Build Coastguard Worker #include "base/base_export.h" 12*635a8641SAndroid Build Coastguard Worker #include "base/macros.h" 13*635a8641SAndroid Build Coastguard Worker #include "base/strings/string_piece.h" 14*635a8641SAndroid Build Coastguard Worker 15*635a8641SAndroid Build Coastguard Worker namespace logging { 16*635a8641SAndroid Build Coastguard Worker 17*635a8641SAndroid Build Coastguard Worker // A helper class containing all the settings for vlogging. 18*635a8641SAndroid Build Coastguard Worker class BASE_EXPORT VlogInfo { 19*635a8641SAndroid Build Coastguard Worker public: 20*635a8641SAndroid Build Coastguard Worker static const int kDefaultVlogLevel; 21*635a8641SAndroid Build Coastguard Worker 22*635a8641SAndroid Build Coastguard Worker // |v_switch| gives the default maximal active V-logging level; 0 is 23*635a8641SAndroid Build Coastguard Worker // the default. Normally positive values are used for V-logging 24*635a8641SAndroid Build Coastguard Worker // levels. 25*635a8641SAndroid Build Coastguard Worker // 26*635a8641SAndroid Build Coastguard Worker // |vmodule_switch| gives the per-module maximal V-logging levels to 27*635a8641SAndroid Build Coastguard Worker // override the value given by |v_switch|. 28*635a8641SAndroid Build Coastguard Worker // E.g. "my_module=2,foo*=3" would change the logging level for all 29*635a8641SAndroid Build Coastguard Worker // code in source files "my_module.*" and "foo*.*" ("-inl" suffixes 30*635a8641SAndroid Build Coastguard Worker // are also disregarded for this matching). 31*635a8641SAndroid Build Coastguard Worker // 32*635a8641SAndroid Build Coastguard Worker // |log_severity| points to an int that stores the log level. If a valid 33*635a8641SAndroid Build Coastguard Worker // |v_switch| is provided, it will set the log level, and the default 34*635a8641SAndroid Build Coastguard Worker // vlog severity will be read from there.. 35*635a8641SAndroid Build Coastguard Worker // 36*635a8641SAndroid Build Coastguard Worker // Any pattern containing a forward or backward slash will be tested 37*635a8641SAndroid Build Coastguard Worker // against the whole pathname and not just the module. E.g., 38*635a8641SAndroid Build Coastguard Worker // "*/foo/bar/*=2" would change the logging level for all code in 39*635a8641SAndroid Build Coastguard Worker // source files under a "foo/bar" directory. 40*635a8641SAndroid Build Coastguard Worker VlogInfo(const std::string& v_switch, 41*635a8641SAndroid Build Coastguard Worker const std::string& vmodule_switch, 42*635a8641SAndroid Build Coastguard Worker int* min_log_level); 43*635a8641SAndroid Build Coastguard Worker ~VlogInfo(); 44*635a8641SAndroid Build Coastguard Worker 45*635a8641SAndroid Build Coastguard Worker // Returns the vlog level for a given file (usually taken from 46*635a8641SAndroid Build Coastguard Worker // __FILE__). 47*635a8641SAndroid Build Coastguard Worker int GetVlogLevel(const base::StringPiece& file) const; 48*635a8641SAndroid Build Coastguard Worker 49*635a8641SAndroid Build Coastguard Worker private: 50*635a8641SAndroid Build Coastguard Worker void SetMaxVlogLevel(int level); 51*635a8641SAndroid Build Coastguard Worker int GetMaxVlogLevel() const; 52*635a8641SAndroid Build Coastguard Worker 53*635a8641SAndroid Build Coastguard Worker // VmodulePattern holds all the information for each pattern parsed 54*635a8641SAndroid Build Coastguard Worker // from |vmodule_switch|. 55*635a8641SAndroid Build Coastguard Worker struct VmodulePattern; 56*635a8641SAndroid Build Coastguard Worker std::vector<VmodulePattern> vmodule_levels_; 57*635a8641SAndroid Build Coastguard Worker int* min_log_level_; 58*635a8641SAndroid Build Coastguard Worker 59*635a8641SAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(VlogInfo); 60*635a8641SAndroid Build Coastguard Worker }; 61*635a8641SAndroid Build Coastguard Worker 62*635a8641SAndroid Build Coastguard Worker // Returns true if the string passed in matches the vlog pattern. The 63*635a8641SAndroid Build Coastguard Worker // vlog pattern string can contain wildcards like * and ?. ? matches 64*635a8641SAndroid Build Coastguard Worker // exactly one character while * matches 0 or more characters. Also, 65*635a8641SAndroid Build Coastguard Worker // as a special case, a / or \ character matches either / or \. 66*635a8641SAndroid Build Coastguard Worker // 67*635a8641SAndroid Build Coastguard Worker // Examples: 68*635a8641SAndroid Build Coastguard Worker // "kh?n" matches "khan" but not "khn" or "khaan" 69*635a8641SAndroid Build Coastguard Worker // "kh*n" matches "khn", "khan", or even "khaaaaan" 70*635a8641SAndroid Build Coastguard Worker // "/foo\bar" matches "/foo/bar", "\foo\bar", or "/foo\bar" 71*635a8641SAndroid Build Coastguard Worker // (disregarding C escaping rules) 72*635a8641SAndroid Build Coastguard Worker BASE_EXPORT bool MatchVlogPattern(const base::StringPiece& string, 73*635a8641SAndroid Build Coastguard Worker const base::StringPiece& vlog_pattern); 74*635a8641SAndroid Build Coastguard Worker 75*635a8641SAndroid Build Coastguard Worker } // namespace logging 76*635a8641SAndroid Build Coastguard Worker 77*635a8641SAndroid Build Coastguard Worker #endif // BASE_VLOG_H_ 78