Chromium Code Reviews| Index: chrome/browser/net/net_log_logger.cc |
| =================================================================== |
| --- chrome/browser/net/net_log_logger.cc (revision 70414) |
| +++ chrome/browser/net/net_log_logger.cc (working copy) |
| @@ -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() {} |
| @@ -22,7 +30,16 @@ |
| source, phase, |
| params, true)); |
| std::string json; |
| - base::JSONWriter::Write(value.get(), true, &json); |
| - VLOG(1) << json; |
| + if (!file_.get()) { |
| + base::JSONWriter::Write(value.get(), true, &json); |
|
eroman
2011/01/12 05:57:34
I don't think we should do pretty printing anymore
mmenke
2011/01/13 03:45:29
Sounds reasonable. Done.
|
| + VLOG(1) << json; |
| + } else { |
| + // 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. |
| + base::JSONWriter::Write(value.get(), false, &json); |
| + fprintf(file_.get(), "%s\n", json.c_str()); |
| + } |
| } |