diff options
author | mmenke@google.com <mmenke@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 00:09:07 +0000 |
---|---|---|
committer | mmenke@google.com <mmenke@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 00:09:07 +0000 |
commit | 44d33b4816fa103086266bf77030e8bec2336a22 (patch) | |
tree | 00df51214d9a88102313f44af84a60b6851f7b27 /chrome/browser/net | |
parent | a1be9ffd087904ffef1749db5048c3d49588fbb4 (diff) | |
download | chromium_src-44d33b4816fa103086266bf77030e8bec2336a22.zip chromium_src-44d33b4816fa103086266bf77030e8bec2336a22.tar.gz chromium_src-44d33b4816fa103086266bf77030e8bec2336a22.tar.bz2 |
Adds the ability to load JSON log files to about:net-internals.
Only works with logs created by the new "--log-net-log=file",
which writes NetLog events to the specified file, regardless
of other logging command line parameters.
Using "--log-net-log" without a file name will just write
NetLog events to VLOG(1), as before.
BUG=63687
TEST=None
Review URL: http://codereview.chromium.org/6025017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72567 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/chrome_net_log.cc | 3 | ||||
-rw-r--r-- | chrome/browser/net/net_log_logger.cc | 22 | ||||
-rw-r--r-- | chrome/browser/net/net_log_logger.h | 17 |
3 files changed, 35 insertions, 7 deletions
diff --git a/chrome/browser/net/chrome_net_log.cc b/chrome/browser/net/chrome_net_log.cc index 58fe6ad..39ebe79 100644 --- a/chrome/browser/net/chrome_net_log.cc +++ b/chrome/browser/net/chrome_net_log.cc @@ -67,7 +67,8 @@ ChromeNetLog::ChromeNetLog() const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kLogNetLog)) { - net_log_logger_.reset(new NetLogLogger()); + net_log_logger_.reset(new NetLogLogger( + command_line.GetSwitchValuePath(switches::kLogNetLog))); AddObserver(net_log_logger_.get()); } } diff --git a/chrome/browser/net/net_log_logger.cc b/chrome/browser/net/net_log_logger.cc index bba75ca..1468e6f 100644 --- a/chrome/browser/net/net_log_logger.cc +++ b/chrome/browser/net/net_log_logger.cc @@ -4,11 +4,19 @@ #include "chrome/browser/net/net_log_logger.h" +#include <stdio.h> + +#include "base/file_util.h" #include "base/json/json_writer.h" +#include "base/threading/thread_restrictions.h" #include "base/values.h" -NetLogLogger::NetLogLogger() +NetLogLogger::NetLogLogger(const FilePath &log_path) : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES) { + if (!log_path.empty()) { + base::ThreadRestrictions::ScopedAllowIO allow_io; + file_.Set(file_util::OpenFile(log_path, "w")); + } } NetLogLogger::~NetLogLogger() {} @@ -21,8 +29,16 @@ void NetLogLogger::OnAddEntry(net::NetLog::EventType type, scoped_ptr<Value> value(net::NetLog::EntryToDictionaryValue(type, time, source, phase, params, true)); + // Don't pretty print, so each JSON value occupies a single line, with no + // breaks (Line breaks in any text field will be escaped). Using strings + // instead of integer identifiers allows logs from older versions to be + // loaded, though a little extra parsing has to be done when loading a log. std::string json; - base::JSONWriter::Write(value.get(), true, &json); - VLOG(1) << json; + base::JSONWriter::Write(value.get(), false, &json); + if (!file_.get()) { + VLOG(1) << json; + } else { + fprintf(file_.get(), "%s\n", json.c_str()); + } } diff --git a/chrome/browser/net/net_log_logger.h b/chrome/browser/net/net_log_logger.h index 564f232..2cb88c6 100644 --- a/chrome/browser/net/net_log_logger.h +++ b/chrome/browser/net/net_log_logger.h @@ -6,14 +6,23 @@ #define CHROME_BROWSER_NET_NET_LOG_LOGGER_H_ #pragma once +#include "base/scoped_handle.h" #include "chrome/browser/net/chrome_net_log.h" +class FilePath; + // NetLogLogger watches the NetLog event stream, and sends all entries to -// VLOG(1). This is to debug errors that prevent getting to the -// about:net-internals page. +// VLOG(1) or a path specified on creation. This is to debug errors that +// prevent getting to the about:net-internals page. +// +// Relies on ChromeNetLog only calling an Observer once at a time for +// thread-safety. class NetLogLogger : public ChromeNetLog::ThreadSafeObserver { public: - NetLogLogger(); + // If |log_path| is empty or file creation fails, writes to VLOG(1). + // Otherwise, writes to |log_path|. Uses one line per entry, for + // easy parsing. + explicit NetLogLogger(const FilePath &log_path); ~NetLogLogger(); // ThreadSafeObserver implementation: @@ -24,6 +33,8 @@ class NetLogLogger : public ChromeNetLog::ThreadSafeObserver { net::NetLog::EventParameters* params); private: + ScopedStdioHandle file_; + DISALLOW_COPY_AND_ASSIGN(NetLogLogger); }; |