vlog.h 2.7 KB

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