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