vlog.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/macros.h"
  10. #include "base/strings/string_piece.h"
  11. namespace logging {
  12. // A helper class containing all the settings for vlogging.
  13. class BASE_EXPORT VlogInfo {
  14. public:
  15. static const int kDefaultVlogLevel;
  16. // |v_switch| gives the default maximal active V-logging level; 0 is
  17. // the default. Normally positive values are used for V-logging
  18. // levels.
  19. //
  20. // |vmodule_switch| gives the per-module maximal V-logging levels to
  21. // override the value given by |v_switch|.
  22. // E.g. "my_module=2,foo*=3" would change the logging level for all
  23. // code in source files "my_module.*" and "foo*.*" ("-inl" suffixes
  24. // are also disregarded for this matching).
  25. //
  26. // |log_severity| points to an int that stores the log level. If a valid
  27. // |v_switch| is provided, it will set the log level, and the default
  28. // vlog severity will be read from there..
  29. //
  30. // Any pattern containing a forward or backward slash will be tested
  31. // against the whole pathname and not just the module. E.g.,
  32. // "*/foo/bar/*=2" would change the logging level for all code in
  33. // source files under a "foo/bar" directory.
  34. VlogInfo(const std::string& v_switch,
  35. const std::string& vmodule_switch,
  36. int* min_log_level);
  37. ~VlogInfo();
  38. // Returns the vlog level for a given file (usually taken from
  39. // __FILE__).
  40. int GetVlogLevel(const base::StringPiece& file) const;
  41. private:
  42. void SetMaxVlogLevel(int level);
  43. int GetMaxVlogLevel() const;
  44. // VmodulePattern holds all the information for each pattern parsed
  45. // from |vmodule_switch|.
  46. struct VmodulePattern;
  47. std::vector<VmodulePattern> vmodule_levels_;
  48. int* min_log_level_;
  49. DISALLOW_COPY_AND_ASSIGN(VlogInfo);
  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_