OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/webrtc_logging.h" | 5 #include "content/renderer/media/webrtc_logging.h" |
6 | 6 |
7 #include <iomanip> | |
8 #include <sstream> | |
9 | |
10 #include "base/time/time.h" | 7 #include "base/time/time.h" |
11 #include "content/public/renderer/webrtc_log_message_delegate.h" | 8 #include "content/public/renderer/webrtc_log_message_delegate.h" |
12 #include "third_party/libjingle/overrides/talk/base/logging.h" | 9 #include "third_party/libjingle/overrides/talk/base/logging.h" |
13 | 10 |
14 namespace content { | 11 namespace content { |
15 | 12 |
16 // Shall only be set once and never go back to NULL. | 13 // Shall only be set once and never go back to NULL. |
17 WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; | 14 WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; |
18 uint64 g_started_time_ms_ = 0; | |
19 | 15 |
20 void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { | 16 void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { |
21 CHECK(!g_webrtc_logging_delegate); | 17 CHECK(!g_webrtc_logging_delegate); |
22 CHECK(delegate); | 18 CHECK(delegate); |
23 | 19 |
24 g_webrtc_logging_delegate = delegate; | 20 g_webrtc_logging_delegate = delegate; |
25 | |
26 g_started_time_ms_ = base::Time::Now().ToInternalValue() / | |
27 base::Time::kMicrosecondsPerMillisecond; | |
28 } | 21 } |
29 | 22 |
30 void WebRtcLogMessageWithTimestamp(const std::string& message) { | 23 void InitWebRtcLogging() { |
| 24 // Log messages from Libjingle should not have timestamps. |
| 25 talk_base::InitDiagnosticLoggingDelegateFunction(&WebRtcLogMessage); |
| 26 } |
| 27 |
| 28 void WebRtcLogMessage(const std::string& message) { |
31 if (g_webrtc_logging_delegate) | 29 if (g_webrtc_logging_delegate) |
32 g_webrtc_logging_delegate->LogMessage(message); | 30 g_webrtc_logging_delegate->LogMessage(message); |
33 } | 31 } |
34 | 32 |
35 void InitWebRtcLogging() { | |
36 // Log messages from Libjingle should always have timestamps. | |
37 talk_base::InitDiagnosticLoggingDelegateFunction( | |
38 WebRtcLogMessageWithTimestamp); | |
39 } | |
40 | |
41 void WebRtcLogMessage(const std::string& message) { | |
42 // Keep consistent with talk_base::DiagnosticLogMessage::CreateTimestamp. | |
43 // TODO(grunell): remove the duplicated code and unify the timestamp creation. | |
44 uint64 now_us = base::Time::Now().ToInternalValue(); | |
45 uint64 interval_ms = now_us / base::Time::kMicrosecondsPerMillisecond - | |
46 g_started_time_ms_; | |
47 | |
48 std::ostringstream message_oss; | |
49 message_oss << "[" << std::setfill('0') << std::setw(3) | |
50 << (interval_ms / 1000) | |
51 << ":" << std::setw(3) | |
52 << (interval_ms % 1000) | |
53 << std::setfill(' ') << "] " << message; | |
54 | |
55 WebRtcLogMessageWithTimestamp(message_oss.str()); | |
56 } | |
57 | |
58 } // namespace content | 33 } // namespace content |
OLD | NEW |