blob: 2950904c55dc0859f2007b3a48e9197e98390a4e [file] [log] [blame]
[email protected]26fbf802011-03-25 18:48:031// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]99b7c57f2010-09-29 19:26:362// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_VLOG_H_
6#define BASE_VLOG_H_
[email protected]99b7c57f2010-09-29 19:26:367
[email protected]99b7c57f2010-09-29 19:26:368#include <string>
[email protected]99b7c57f2010-09-29 19:26:369#include <vector>
10
[email protected]0bea7252011-08-05 15:34:0011#include "base/base_export.h"
avi9b6f42932015-12-26 22:15:1412#include "base/macros.h"
[email protected]eb62f7262013-03-30 14:29:0013#include "base/strings/string_piece.h"
[email protected]99b7c57f2010-09-29 19:26:3614
15namespace logging {
16
17// A helper class containing all the settings for vlogging.
[email protected]0bea7252011-08-05 15:34:0018class BASE_EXPORT VlogInfo {
[email protected]99b7c57f2010-09-29 19:26:3619 public:
[email protected]eae9c062011-01-11 00:50:5920 static const int kDefaultVlogLevel;
21
[email protected]99b7c57f2010-09-29 19:26:3622 // |v_switch| gives the default maximal active V-logging level; 0 is
23 // the default. Normally positive values are used for V-logging
24 // levels.
25 //
26 // |vmodule_switch| gives the per-module maximal V-logging levels to
27 // override the value given by |v_switch|.
28 // E.g. "my_module=2,foo*=3" would change the logging level for all
29 // code in source files "my_module.*" and "foo*.*" ("-inl" suffixes
30 // are also disregarded for this matching).
[email protected]b0d38d4c2010-10-29 00:39:4831 //
[email protected]162ac0f2010-11-04 15:50:4932 // |log_severity| points to an int that stores the log level. If a valid
33 // |v_switch| is provided, it will set the log level, and the default
34 // vlog severity will be read from there..
35 //
[email protected]b0d38d4c2010-10-29 00:39:4836 // Any pattern containing a forward or backward slash will be tested
37 // against the whole pathname and not just the module. E.g.,
38 // "*/foo/bar/*=2" would change the logging level for all code in
39 // source files under a "foo/bar" directory.
[email protected]99b7c57f2010-09-29 19:26:3640 VlogInfo(const std::string& v_switch,
[email protected]162ac0f2010-11-04 15:50:4941 const std::string& vmodule_switch,
42 int* min_log_level);
[email protected]1889dc1b2010-10-14 22:03:1343 ~VlogInfo();
[email protected]99b7c57f2010-09-29 19:26:3644
45 // Returns the vlog level for a given file (usually taken from
46 // __FILE__).
[email protected]162ac0f2010-11-04 15:50:4947 int GetVlogLevel(const base::StringPiece& file) const;
[email protected]99b7c57f2010-09-29 19:26:3648
[email protected]99b7c57f2010-09-29 19:26:3649 private:
[email protected]162ac0f2010-11-04 15:50:4950 void SetMaxVlogLevel(int level);
51 int GetMaxVlogLevel() const;
52
[email protected]b0d38d4c2010-10-29 00:39:4853 // VmodulePattern holds all the information for each pattern parsed
54 // from |vmodule_switch|.
[email protected]eae9c062011-01-11 00:50:5955 struct VmodulePattern;
[email protected]99b7c57f2010-09-29 19:26:3656 std::vector<VmodulePattern> vmodule_levels_;
[email protected]162ac0f2010-11-04 15:50:4957 int* min_log_level_;
[email protected]99b7c57f2010-09-29 19:26:3658
59 DISALLOW_COPY_AND_ASSIGN(VlogInfo);
60};
61
[email protected]e11de722010-11-01 20:50:5562// Returns true if the string passed in matches the vlog pattern. The
63// vlog pattern string can contain wildcards like * and ?. ? matches
64// exactly one character while * matches 0 or more characters. Also,
65// as a special case, a / or \ character matches either / or \.
66//
67// Examples:
68// "kh?n" matches "khan" but not "khn" or "khaan"
69// "kh*n" matches "khn", "khan", or even "khaaaaan"
70// "/foo\bar" matches "/foo/bar", "\foo\bar", or "/foo\bar"
71// (disregarding C escaping rules)
[email protected]0bea7252011-08-05 15:34:0072BASE_EXPORT bool MatchVlogPattern(const base::StringPiece& string,
73 const base::StringPiece& vlog_pattern);
[email protected]e11de722010-11-01 20:50:5574
[email protected]99b7c57f2010-09-29 19:26:3675} // namespace logging
76
77#endif // BASE_VLOG_H_