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