More bring up of ui code on iOS.
[chromium-blink-merge.git] / sync / engine / traffic_logger.cc
blob740409aac256be07eeed7d9f5e494bc1902d9cd0
1 // Copyright (c) 2012 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.
5 #include "sync/engine/traffic_logger.h"
7 #include <string>
9 #include "base/json/json_writer.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "sync/protocol/proto_value_conversions.h"
14 #include "sync/protocol/sync.pb.h"
16 namespace syncer {
18 namespace {
19 template <class T>
20 void LogData(const T& data,
21 DictionaryValue* (*to_dictionary_value)(const T&, bool),
22 const std::string& description) {
23 if (::logging::DEBUG_MODE && VLOG_IS_ON(1)) {
24 scoped_ptr<DictionaryValue> value(
25 (*to_dictionary_value)(data, true /* include_specifics */));
26 std::string message;
27 base::JSONWriter::WriteWithOptions(value.get(),
28 base::JSONWriter::OPTIONS_PRETTY_PRINT,
29 &message);
30 DVLOG(1) << "\n" << description << "\n" << message << "\n";
33 } // namespace
35 void LogClientToServerMessage(const sync_pb::ClientToServerMessage& msg) {
36 LogData(msg, &ClientToServerMessageToValue,
37 "******Client To Server Message******");
40 void LogClientToServerResponse(
41 const sync_pb::ClientToServerResponse& response) {
42 LogData(response, &ClientToServerResponseToValue,
43 "******Server Response******");
46 } // namespace syncer