| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "third_party/libjingle/overrides/talk/base/logging.h" | 5 #include "third_party/libjingle/overrides/talk/base/logging.h" |
| 6 | 6 |
| 7 #if defined(OS_MACOSX) && !defined(OS_IOS) | 7 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
| 9 #endif // OS_MACOSX | 9 #endif // OS_MACOSX |
| 10 | 10 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 int line, | 125 int line, |
| 126 LoggingSeverity severity, | 126 LoggingSeverity severity, |
| 127 bool log_to_chrome, | 127 bool log_to_chrome, |
| 128 LogErrorContext err_ctx, | 128 LogErrorContext err_ctx, |
| 129 int err) | 129 int err) |
| 130 : file_name_(file), | 130 : file_name_(file), |
| 131 line_(line), | 131 line_(line), |
| 132 severity_(severity), | 132 severity_(severity), |
| 133 log_to_chrome_(log_to_chrome) { | 133 log_to_chrome_(log_to_chrome) { |
| 134 extra_ = GenerateExtra(err_ctx, err, NULL); | 134 extra_ = GenerateExtra(err_ctx, err, NULL); |
| 135 CreateTimestamp(); | |
| 136 } | 135 } |
| 137 | 136 |
| 138 DiagnosticLogMessage::DiagnosticLogMessage(const char* file, | 137 DiagnosticLogMessage::DiagnosticLogMessage(const char* file, |
| 139 int line, | 138 int line, |
| 140 LoggingSeverity severity, | 139 LoggingSeverity severity, |
| 141 bool log_to_chrome, | 140 bool log_to_chrome, |
| 142 LogErrorContext err_ctx, | 141 LogErrorContext err_ctx, |
| 143 int err, | 142 int err, |
| 144 const char* module) | 143 const char* module) |
| 145 : file_name_(file), | 144 : file_name_(file), |
| 146 line_(line), | 145 line_(line), |
| 147 severity_(severity), | 146 severity_(severity), |
| 148 log_to_chrome_(log_to_chrome) { | 147 log_to_chrome_(log_to_chrome) { |
| 149 extra_ = GenerateExtra(err_ctx, err, module); | 148 extra_ = GenerateExtra(err_ctx, err, module); |
| 150 CreateTimestamp(); | |
| 151 } | 149 } |
| 152 | 150 |
| 153 DiagnosticLogMessage::~DiagnosticLogMessage() { | 151 DiagnosticLogMessage::~DiagnosticLogMessage() { |
| 154 print_stream_ << extra_; | 152 print_stream_ << extra_; |
| 155 const std::string& str = print_stream_.str(); | 153 const std::string& str = print_stream_.str(); |
| 156 if (log_to_chrome_) | 154 if (log_to_chrome_) |
| 157 LOG_LAZY_STREAM_DIRECT(file_name_, line_, severity_) << str; | 155 LOG_LAZY_STREAM_DIRECT(file_name_, line_, severity_) << str; |
| 158 if (g_logging_delegate_function && severity_ <= LS_INFO) { | 156 if (g_logging_delegate_function && severity_ <= LS_INFO) { |
| 159 print_stream_with_timestamp_ << str; | 157 g_logging_delegate_function(str); |
| 160 g_logging_delegate_function(print_stream_with_timestamp_.str()); | |
| 161 } | 158 } |
| 162 } | 159 } |
| 163 | 160 |
| 164 void DiagnosticLogMessage::CreateTimestamp() { | |
| 165 #if !defined(ANDROID) | |
| 166 static const uint32 g_logging_start_time = talk_base::Time(); | |
| 167 uint32 time = talk_base::TimeSince(g_logging_start_time); | |
| 168 print_stream_with_timestamp_ << "[" << std::setfill('0') | |
| 169 << std::setw(3) << (time / 1000) | |
| 170 << ":" << std::setw(3) << (time % 1000) | |
| 171 << std::setfill(' ') << "] "; | |
| 172 #endif | |
| 173 } | |
| 174 | |
| 175 // Note: this function is a copy from the overriden libjingle implementation. | 161 // Note: this function is a copy from the overriden libjingle implementation. |
| 176 void LogMultiline(LoggingSeverity level, const char* label, bool input, | 162 void LogMultiline(LoggingSeverity level, const char* label, bool input, |
| 177 const void* data, size_t len, bool hex_mode, | 163 const void* data, size_t len, bool hex_mode, |
| 178 LogMultilineState* state) { | 164 LogMultilineState* state) { |
| 179 if (!LOG_CHECK_LEVEL_V(level)) | 165 if (!LOG_CHECK_LEVEL_V(level)) |
| 180 return; | 166 return; |
| 181 | 167 |
| 182 const char * direction = (input ? " << " : " >> "); | 168 const char * direction = (input ? " << " : " >> "); |
| 183 | 169 |
| 184 // NULL data means to flush our count of unprintable characters. | 170 // NULL data means to flush our count of unprintable characters. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 302 } |
| 317 | 303 |
| 318 void SetExtraLoggingInit( | 304 void SetExtraLoggingInit( |
| 319 void (*function)(void (*delegate)(const std::string&))) { | 305 void (*function)(void (*delegate)(const std::string&))) { |
| 320 CHECK(function); | 306 CHECK(function); |
| 321 CHECK(!g_extra_logging_init_function); | 307 CHECK(!g_extra_logging_init_function); |
| 322 g_extra_logging_init_function = function; | 308 g_extra_logging_init_function = function; |
| 323 } | 309 } |
| 324 | 310 |
| 325 } // namespace talk_base | 311 } // namespace talk_base |
| OLD | NEW |