Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3293)

Unified Diff: base/vlog.cc

Issue 3448028: Implemented VLOG() et al. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Addressed evmar's comments Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/vlog.h ('k') | base/vlog_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/vlog.cc
diff --git a/base/vlog.cc b/base/vlog.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d6c3eb7f56fc5bfe812e93c43589e1ea85a45013
--- /dev/null
+++ b/base/vlog.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/vlog.h"
+
+#include "base/basictypes.h"
+#include "base/string_number_conversions.h"
+#include "base/string_split.h"
+#include "base/string_util.h"
+
+namespace logging {
+
+const int VlogInfo::kDefaultVlogLevel = 0;
+
+VlogInfo::VlogInfo(const std::string& v_switch,
+ const std::string& vmodule_switch)
+ : max_vlog_level_(kDefaultVlogLevel) {
+ typedef std::pair<std::string, std::string> KVPair;
+ if (!base::StringToInt(v_switch, &max_vlog_level_)) {
+ LOG(WARNING) << "Parsed v switch \""
+ << v_switch << "\" as " << max_vlog_level_;
+ }
+ std::vector<KVPair> kv_pairs;
+ if (!base::SplitStringIntoKeyValuePairs(
+ vmodule_switch, '=', ',', &kv_pairs)) {
+ LOG(WARNING) << "Could not fully parse vmodule switch \""
+ << vmodule_switch << "\"";
+ }
+ for (std::vector<KVPair>::const_iterator it = kv_pairs.begin();
+ it != kv_pairs.end(); ++it) {
+ int vlog_level = kDefaultVlogLevel;
+ if (!base::StringToInt(it->second, &vlog_level)) {
+ LOG(WARNING) << "Parsed vlog level for \""
+ << it->first << "=" << it->second
+ << "\" as " << vlog_level;
+ }
+ vmodule_levels_.push_back(std::make_pair(it->first, vlog_level));
+ }
+}
+
+int VlogInfo::GetVlogLevel(const base::StringPiece& file) {
+ if (!vmodule_levels_.empty()) {
+ base::StringPiece module(file);
+ base::StringPiece::size_type last_slash_pos =
+ module.find_last_of("\\/");
+ if (last_slash_pos != base::StringPiece::npos) {
+ module.remove_prefix(last_slash_pos + 1);
+ }
+ base::StringPiece::size_type extension_start = module.find('.');
+ module = module.substr(0, extension_start);
+ static const char kInlSuffix[] = "-inl";
+ static const int kInlSuffixLen = arraysize(kInlSuffix) - 1;
+ if (module.ends_with(kInlSuffix)) {
+ module.remove_suffix(kInlSuffixLen);
+ }
+ for (std::vector<VmodulePattern>::const_iterator it =
+ vmodule_levels_.begin(); it != vmodule_levels_.end(); ++it) {
+ // TODO(akalin): Use a less-heavyweight version of MatchPattern
+ // (we can pretty much assume we're dealing with ASCII).
+ if (MatchPattern(module, it->first)) {
+ return it->second;
+ }
+ }
+ }
+ return max_vlog_level_;
+}
+
+} // namespace
« no previous file with comments | « base/vlog.h ('k') | base/vlog_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698