| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "rtc_base/logging.h" |
| 12 |
| 13 | #include <string.h> |
| 14 |
| 15 | #if RTC_LOG_ENABLED() |
| 16 |
| 17 | #if defined(WEBRTC_WIN) |
| 18 | #include <windows.h> |
| 19 | #if _MSC_VER < 1900 |
| 20 | #define snprintf _snprintf |
| 21 | #endif |
| 22 | #undef ERROR // wingdi.h |
| 23 | #endif |
| 24 |
| 25 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 26 | #include <CoreServices/CoreServices.h> |
| 27 | #elif defined(WEBRTC_ANDROID) |
| 28 | #include <android/log.h> |
| 29 |
| 30 | // Android has a 1024 limit on log inputs. We use 60 chars as an |
| 31 | // approx for the header/tag portion. |
| 32 | // See android/system/core/liblog/logd_write.c |
| 33 | static const int kMaxLogLineSize = 1024 - 60; |
| 34 | #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) || WEBRTC_ANDROID |
| 35 |
| 36 | #include <inttypes.h> |
| 37 | #include <stdio.h> |
| 38 | #include <time.h> |
| 39 |
| 40 | #include <algorithm> |
| 41 | #include <cstdarg> |
| 42 | #include <vector> |
| 43 |
| 44 | #include "absl/base/attributes.h" |
| 45 | #include "rtc_base/checks.h" |
| 46 | #include "rtc_base/platform_thread_types.h" |
| 47 | #include "rtc_base/string_encode.h" |
| 48 | #include "rtc_base/string_utils.h" |
| 49 | #include "rtc_base/strings/string_builder.h" |
| 50 | #include "rtc_base/synchronization/mutex.h" |
| 51 | #include "rtc_base/thread_annotations.h" |
| 52 | #include "rtc_base/time_utils.h" |
| 53 |
| 54 | #if defined(WEBRTC_RACE_CHECK_MUTEX) |
| 55 | #if defined(WEBRTC_ABSL_MUTEX) |
| 56 | #error Please only define one of WEBRTC_RACE_CHECK_MUTEX and WEBRTC_ABSL_MUTEX. |
| 57 | #endif |
| 58 | #include "absl/base/const_init.h" |
| 59 | #include "absl/synchronization/mutex.h" // nogncheck |
| 60 | using LoggingMutexLock = ::absl::MutexLock; |
| 61 | #else |
| 62 | using LoggingMutexLock = ::webrtc::MutexLock; |
| 63 | #endif // if defined(WEBRTC_RACE_CHECK_MUTEX) |
| 64 |
| 65 | namespace rtc { |
| 66 | namespace { |
| 67 | // By default, release builds don't log, debug builds at info level |
| 68 | #if !defined(NDEBUG) |
| 69 | static LoggingSeverity g_min_sev = LS_INFO; |
| 70 | static LoggingSeverity g_dbg_sev = LS_INFO; |
| 71 | #else |
| 72 | static LoggingSeverity g_min_sev = LS_NONE; |
| 73 | static LoggingSeverity g_dbg_sev = LS_NONE; |
| 74 | #endif |
| 75 |
| 76 | // Return the filename portion of the string (that following the last slash). |
| 77 | const char* FilenameFromPath(const char* file) { |
| 78 | const char* end1 = ::strrchr(file, '/'); |
| 79 | const char* end2 = ::strrchr(file, '\\'); |
| 80 | if (!end1 && !end2) |
| 81 | return file; |
| 82 | else |
| 83 | return (end1 > end2) ? end1 + 1 : end2 + 1; |
| 84 | } |
| 85 |
| 86 | // Global lock for log subsystem, only needed to serialize access to streams_. |
| 87 | // TODO(bugs.webrtc.org/11665): this is not currently constant initialized and |
| 88 | // trivially destructible. |
| 89 | #if defined(WEBRTC_RACE_CHECK_MUTEX) |
| 90 | // When WEBRTC_RACE_CHECK_MUTEX is defined, even though WebRTC objects are |
| 91 | // invoked serially, the logging is static, invoked concurrently and hence needs |
| 92 | // protection. |
| 93 | absl::Mutex g_log_mutex_(absl::kConstInit); |
| 94 | #else |
| 95 | webrtc::Mutex g_log_mutex_; |
| 96 | #endif |
| 97 |
| 98 | } // namespace |
| 99 |
| 100 | ///////////////////////////////////////////////////////////////////////////// |
| 101 | // LogMessage |
| 102 | ///////////////////////////////////////////////////////////////////////////// |
| 103 |
| 104 | bool LogMessage::log_to_stderr_ = true; |
| 105 |
| 106 | // The list of logging streams currently configured. |
| 107 | // Note: we explicitly do not clean this up, because of the uncertain ordering |
| 108 | // of destructors at program exit. Let the person who sets the stream trigger |
| 109 | // cleanup by setting to null, or let it leak (safe at program exit). |
| 110 | ABSL_CONST_INIT LogSink* LogMessage::streams_ RTC_GUARDED_BY(g_log_mutex_) = |
| 111 | nullptr; |
| 112 | ABSL_CONST_INIT std::atomic<bool> LogMessage::streams_empty_ = {true}; |
| 113 |
| 114 | // Boolean options default to false (0) |
| 115 | bool LogMessage::thread_, LogMessage::timestamp_; |
| 116 |
| 117 | LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev) |
| 118 | : LogMessage(file, line, sev, ERRCTX_NONE, 0) {} |
| 119 |
| 120 | LogMessage::LogMessage(const char* file, |
| 121 | int line, |
| 122 | LoggingSeverity sev, |
| 123 | LogErrorContext err_ctx, |
| 124 | int err) |
| 125 | : severity_(sev) { |
| 126 | if (timestamp_) { |
| 127 | // Use SystemTimeMillis so that even if tests use fake clocks, the timestamp |
| 128 | // in log messages represents the real system time. |
| 129 | int64_t time = TimeDiff(SystemTimeMillis(), LogStartTime()); |
| 130 | // Also ensure WallClockStartTime is initialized, so that it matches |
| 131 | // LogStartTime. |
| 132 | WallClockStartTime(); |
| 133 | // TODO(kwiberg): Switch to absl::StrFormat, if binary size is ok. |
| 134 | char timestamp[50]; // Maximum string length of an int64_t is 20. |
| 135 | int len = |
| 136 | snprintf(timestamp, sizeof(timestamp), "[%03" PRId64 ":%03" PRId64 "]", |
| 137 | time / 1000, time % 1000); |
| 138 | RTC_DCHECK_LT(len, sizeof(timestamp)); |
| 139 | print_stream_ << timestamp; |
| 140 | } |
| 141 |
| 142 | if (thread_) { |
| 143 | PlatformThreadId id = CurrentThreadId(); |
| 144 | print_stream_ << "[" << id << "] "; |
| 145 | } |
| 146 |
| 147 | if (file != nullptr) { |
| 148 | #if defined(WEBRTC_ANDROID) |
| 149 | tag_ = FilenameFromPath(file); |
| 150 | print_stream_ << "(line " << line << "): "; |
| 151 | #else |
| 152 | print_stream_ << "(" << FilenameFromPath(file) << ":" << line << "): "; |
| 153 | #endif |
| 154 | } |
| 155 |
| 156 | if (err_ctx != ERRCTX_NONE) { |
| 157 | char tmp_buf[1024]; |
| 158 | SimpleStringBuilder tmp(tmp_buf); |
| 159 | tmp.AppendFormat("[0x%08X]", err); |
| 160 | switch (err_ctx) { |
| 161 | case ERRCTX_ERRNO: |
| 162 | tmp << " " << strerror(err); |
| 163 | break; |
| 164 | #ifdef WEBRTC_WIN |
| 165 | case ERRCTX_HRESULT: { |
| 166 | char msgbuf[256]; |
| 167 | DWORD flags = |
| 168 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; |
| 169 | if (DWORD len = FormatMessageA( |
| 170 | flags, nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 171 | msgbuf, sizeof(msgbuf) / sizeof(msgbuf[0]), nullptr)) { |
| 172 | while ((len > 0) && |
| 173 | isspace(static_cast<unsigned char>(msgbuf[len - 1]))) { |
| 174 | msgbuf[--len] = 0; |
| 175 | } |
| 176 | tmp << " " << msgbuf; |
| 177 | } |
| 178 | break; |
| 179 | } |
| 180 | #endif // WEBRTC_WIN |
| 181 | default: |
| 182 | break; |
| 183 | } |
| 184 | extra_ = tmp.str(); |
| 185 | } |
| 186 | } |
| 187 |
| 188 | #if defined(WEBRTC_ANDROID) |
| 189 | LogMessage::LogMessage(const char* file, |
| 190 | int line, |
| 191 | LoggingSeverity sev, |
| 192 | const char* tag) |
| 193 | : LogMessage(file, line, sev, ERRCTX_NONE, 0 /* err */) { |
| 194 | tag_ = tag; |
| 195 | print_stream_ << tag << ": "; |
| 196 | } |
| 197 | #endif |
| 198 |
| 199 | // DEPRECATED. Currently only used by downstream projects that use |
| 200 | // implementation details of logging.h. Work is ongoing to remove those |
| 201 | // dependencies. |
| 202 | LogMessage::LogMessage(const char* file, |
| 203 | int line, |
| 204 | LoggingSeverity sev, |
| 205 | const std::string& tag) |
| 206 | : LogMessage(file, line, sev) { |
| 207 | print_stream_ << tag << ": "; |
| 208 | } |
| 209 |
| 210 | LogMessage::~LogMessage() { |
| 211 | FinishPrintStream(); |
| 212 |
| 213 | const std::string str = print_stream_.Release(); |
| 214 |
| 215 | if (severity_ >= g_dbg_sev) { |
| 216 | #if defined(WEBRTC_ANDROID) |
| 217 | OutputToDebug(str, severity_, tag_); |
| 218 | #else |
| 219 | OutputToDebug(str, severity_); |
| 220 | #endif |
| 221 | } |
| 222 |
| 223 | LoggingMutexLock lock(&g_log_mutex_); |
| 224 | for (LogSink* entry = streams_; entry != nullptr; entry = entry->next_) { |
| 225 | if (severity_ >= entry->min_severity_) { |
| 226 | #if defined(WEBRTC_ANDROID) |
| 227 | entry->OnLogMessage(str, severity_, tag_); |
| 228 | #else |
| 229 | entry->OnLogMessage(str, severity_); |
| 230 | #endif |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 |
| 235 | void LogMessage::AddTag(const char* tag) { |
| 236 | #ifdef WEBRTC_ANDROID |
| 237 | tag_ = tag; |
| 238 | #endif |
| 239 | } |
| 240 |
| 241 | rtc::StringBuilder& LogMessage::stream() { |
| 242 | return print_stream_; |
| 243 | } |
| 244 |
| 245 | int LogMessage::GetMinLogSeverity() { |
| 246 | return g_min_sev; |
| 247 | } |
| 248 |
| 249 | LoggingSeverity LogMessage::GetLogToDebug() { |
| 250 | return g_dbg_sev; |
| 251 | } |
| 252 | int64_t LogMessage::LogStartTime() { |
| 253 | static const int64_t g_start = SystemTimeMillis(); |
| 254 | return g_start; |
| 255 | } |
| 256 |
| 257 | uint32_t LogMessage::WallClockStartTime() { |
| 258 | static const uint32_t g_start_wallclock = time(nullptr); |
| 259 | return g_start_wallclock; |
| 260 | } |
| 261 |
| 262 | void LogMessage::LogThreads(bool on) { |
| 263 | thread_ = on; |
| 264 | } |
| 265 |
| 266 | void LogMessage::LogTimestamps(bool on) { |
| 267 | timestamp_ = on; |
| 268 | } |
| 269 |
| 270 | void LogMessage::LogToDebug(LoggingSeverity min_sev) { |
| 271 | g_dbg_sev = min_sev; |
| 272 | LoggingMutexLock lock(&g_log_mutex_); |
| 273 | UpdateMinLogSeverity(); |
| 274 | } |
| 275 |
| 276 | void LogMessage::SetLogToStderr(bool log_to_stderr) { |
| 277 | log_to_stderr_ = log_to_stderr; |
| 278 | } |
| 279 |
| 280 | int LogMessage::GetLogToStream(LogSink* stream) { |
| 281 | LoggingMutexLock lock(&g_log_mutex_); |
| 282 | LoggingSeverity sev = LS_NONE; |
| 283 | for (LogSink* entry = streams_; entry != nullptr; entry = entry->next_) { |
| 284 | if (stream == nullptr || stream == entry) { |
| 285 | sev = std::min(sev, entry->min_severity_); |
| 286 | } |
| 287 | } |
| 288 | return sev; |
| 289 | } |
| 290 |
| 291 | void LogMessage::AddLogToStream(LogSink* stream, LoggingSeverity min_sev) { |
| 292 | LoggingMutexLock lock(&g_log_mutex_); |
| 293 | stream->min_severity_ = min_sev; |
| 294 | stream->next_ = streams_; |
| 295 | streams_ = stream; |
| 296 | streams_empty_.store(false, std::memory_order_relaxed); |
| 297 | UpdateMinLogSeverity(); |
| 298 | } |
| 299 |
| 300 | void LogMessage::RemoveLogToStream(LogSink* stream) { |
| 301 | LoggingMutexLock lock(&g_log_mutex_); |
| 302 | for (LogSink** entry = &streams_; *entry != nullptr; |
| 303 | entry = &(*entry)->next_) { |
| 304 | if (*entry == stream) { |
| 305 | *entry = (*entry)->next_; |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | streams_empty_.store(streams_ == nullptr, std::memory_order_relaxed); |
| 310 | UpdateMinLogSeverity(); |
| 311 | } |
| 312 |
| 313 | void LogMessage::ConfigureLogging(const char* params) { |
| 314 | LoggingSeverity current_level = LS_VERBOSE; |
| 315 | LoggingSeverity debug_level = GetLogToDebug(); |
| 316 |
| 317 | std::vector<std::string> tokens; |
| 318 | tokenize(params, ' ', &tokens); |
| 319 |
| 320 | for (const std::string& token : tokens) { |
| 321 | if (token.empty()) |
| 322 | continue; |
| 323 |
| 324 | // Logging features |
| 325 | if (token == "tstamp") { |
| 326 | LogTimestamps(); |
| 327 | } else if (token == "thread") { |
| 328 | LogThreads(); |
| 329 |
| 330 | // Logging levels |
| 331 | } else if (token == "verbose") { |
| 332 | current_level = LS_VERBOSE; |
| 333 | } else if (token == "info") { |
| 334 | current_level = LS_INFO; |
| 335 | } else if (token == "warning") { |
| 336 | current_level = LS_WARNING; |
| 337 | } else if (token == "error") { |
| 338 | current_level = LS_ERROR; |
| 339 | } else if (token == "none") { |
| 340 | current_level = LS_NONE; |
| 341 |
| 342 | // Logging targets |
| 343 | } else if (token == "debug") { |
| 344 | debug_level = current_level; |
| 345 | } |
| 346 | } |
| 347 |
| 348 | #if defined(WEBRTC_WIN) && !defined(WINUWP) |
| 349 | if ((LS_NONE != debug_level) && !::IsDebuggerPresent()) { |
| 350 | // First, attempt to attach to our parent's console... so if you invoke |
| 351 | // from the command line, we'll see the output there. Otherwise, create |
| 352 | // our own console window. |
| 353 | // Note: These methods fail if a console already exists, which is fine. |
| 354 | if (!AttachConsole(ATTACH_PARENT_PROCESS)) |
| 355 | ::AllocConsole(); |
| 356 | } |
| 357 | #endif // defined(WEBRTC_WIN) && !defined(WINUWP) |
| 358 |
| 359 | LogToDebug(debug_level); |
| 360 | } |
| 361 |
| 362 | void LogMessage::UpdateMinLogSeverity() |
| 363 | RTC_EXCLUSIVE_LOCKS_REQUIRED(g_log_mutex_) { |
| 364 | LoggingSeverity min_sev = g_dbg_sev; |
| 365 | for (LogSink* entry = streams_; entry != nullptr; entry = entry->next_) { |
| 366 | min_sev = std::min(min_sev, entry->min_severity_); |
| 367 | } |
| 368 | g_min_sev = min_sev; |
| 369 | } |
| 370 |
| 371 | #if defined(WEBRTC_ANDROID) |
| 372 | void LogMessage::OutputToDebug(const std::string& str, |
| 373 | LoggingSeverity severity, |
| 374 | const char* tag) { |
| 375 | #else |
| 376 | void LogMessage::OutputToDebug(const std::string& str, |
| 377 | LoggingSeverity severity) { |
| 378 | #endif |
| 379 | bool log_to_stderr = log_to_stderr_; |
| 380 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && defined(NDEBUG) |
| 381 | // On the Mac, all stderr output goes to the Console log and causes clutter. |
| 382 | // So in opt builds, don't log to stderr unless the user specifically sets |
| 383 | // a preference to do so. |
| 384 | CFStringRef key = CFStringCreateWithCString( |
| 385 | kCFAllocatorDefault, "logToStdErr", kCFStringEncodingUTF8); |
| 386 | CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle()); |
| 387 | if (key != nullptr && domain != nullptr) { |
| 388 | Boolean exists_and_is_valid; |
| 389 | Boolean should_log = |
| 390 | CFPreferencesGetAppBooleanValue(key, domain, &exists_and_is_valid); |
| 391 | // If the key doesn't exist or is invalid or is false, we will not log to |
| 392 | // stderr. |
| 393 | log_to_stderr = exists_and_is_valid && should_log; |
| 394 | } |
| 395 | if (key != nullptr) { |
| 396 | CFRelease(key); |
| 397 | } |
| 398 | #endif // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && defined(NDEBUG) |
| 399 |
| 400 | #if defined(WEBRTC_WIN) |
| 401 | // Always log to the debugger. |
| 402 | // Perhaps stderr should be controlled by a preference, as on Mac? |
| 403 | OutputDebugStringA(str.c_str()); |
| 404 | if (log_to_stderr) { |
| 405 | // This handles dynamically allocated consoles, too. |
| 406 | if (HANDLE error_handle = ::GetStdHandle(STD_ERROR_HANDLE)) { |
| 407 | log_to_stderr = false; |
| 408 | DWORD written = 0; |
| 409 | ::WriteFile(error_handle, str.data(), static_cast<DWORD>(str.size()), |
| 410 | &written, 0); |
| 411 | } |
| 412 | } |
| 413 | #endif // WEBRTC_WIN |
| 414 |
| 415 | #if defined(WEBRTC_ANDROID) |
| 416 | // Android's logging facility uses severity to log messages but we |
| 417 | // need to map libjingle's severity levels to Android ones first. |
| 418 | // Also write to stderr which maybe available to executable started |
| 419 | // from the shell. |
| 420 | int prio; |
| 421 | switch (severity) { |
| 422 | case LS_VERBOSE: |
| 423 | prio = ANDROID_LOG_VERBOSE; |
| 424 | break; |
| 425 | case LS_INFO: |
| 426 | prio = ANDROID_LOG_INFO; |
| 427 | break; |
| 428 | case LS_WARNING: |
| 429 | prio = ANDROID_LOG_WARN; |
| 430 | break; |
| 431 | case LS_ERROR: |
| 432 | prio = ANDROID_LOG_ERROR; |
| 433 | break; |
| 434 | default: |
| 435 | prio = ANDROID_LOG_UNKNOWN; |
| 436 | } |
| 437 |
| 438 | int size = str.size(); |
| 439 | int line = 0; |
| 440 | int idx = 0; |
| 441 | const int max_lines = size / kMaxLogLineSize + 1; |
| 442 | if (max_lines == 1) { |
| 443 | __android_log_print(prio, tag, "%.*s", size, str.c_str()); |
| 444 | } else { |
| 445 | while (size > 0) { |
| 446 | const int len = std::min(size, kMaxLogLineSize); |
| 447 | // Use the size of the string in the format (str may have \0 in the |
| 448 | // middle). |
| 449 | __android_log_print(prio, tag, "[%d/%d] %.*s", line + 1, max_lines, len, |
| 450 | str.c_str() + idx); |
| 451 | idx += len; |
| 452 | size -= len; |
| 453 | ++line; |
| 454 | } |
| 455 | } |
| 456 | #endif // WEBRTC_ANDROID |
| 457 | if (log_to_stderr) { |
| 458 | fprintf(stderr, "%s", str.c_str()); |
| 459 | fflush(stderr); |
| 460 | } |
| 461 | } |
| 462 |
| 463 | // static |
| 464 | bool LogMessage::IsNoop(LoggingSeverity severity) { |
| 465 | if (severity >= g_dbg_sev || severity >= g_min_sev) |
| 466 | return false; |
| 467 | return streams_empty_.load(std::memory_order_relaxed); |
| 468 | } |
| 469 |
| 470 | void LogMessage::FinishPrintStream() { |
| 471 | if (!extra_.empty()) |
| 472 | print_stream_ << " : " << extra_; |
| 473 | print_stream_ << "\n"; |
| 474 | } |
| 475 |
| 476 | namespace webrtc_logging_impl { |
| 477 |
| 478 | void Log(const LogArgType* fmt, ...) { |
| 479 | va_list args; |
| 480 | va_start(args, fmt); |
| 481 |
| 482 | LogMetadataErr meta; |
| 483 | const char* tag = nullptr; |
| 484 | switch (*fmt) { |
| 485 | case LogArgType::kLogMetadata: { |
| 486 | meta = {va_arg(args, LogMetadata), ERRCTX_NONE, 0}; |
| 487 | break; |
| 488 | } |
| 489 | case LogArgType::kLogMetadataErr: { |
| 490 | meta = va_arg(args, LogMetadataErr); |
| 491 | break; |
| 492 | } |
| 493 | #ifdef WEBRTC_ANDROID |
| 494 | case LogArgType::kLogMetadataTag: { |
| 495 | const LogMetadataTag tag_meta = va_arg(args, LogMetadataTag); |
| 496 | meta = {{nullptr, 0, tag_meta.severity}, ERRCTX_NONE, 0}; |
| 497 | tag = tag_meta.tag; |
| 498 | break; |
| 499 | } |
| 500 | #endif |
| 501 | default: { |
| 502 | RTC_NOTREACHED(); |
| 503 | va_end(args); |
| 504 | return; |
| 505 | } |
| 506 | } |
| 507 |
| 508 | LogMessage log_message(meta.meta.File(), meta.meta.Line(), |
| 509 | meta.meta.Severity(), meta.err_ctx, meta.err); |
| 510 | if (tag) { |
| 511 | log_message.AddTag(tag); |
| 512 | } |
| 513 |
| 514 | for (++fmt; *fmt != LogArgType::kEnd; ++fmt) { |
| 515 | switch (*fmt) { |
| 516 | case LogArgType::kInt: |
| 517 | log_message.stream() << va_arg(args, int); |
| 518 | break; |
| 519 | case LogArgType::kLong: |
| 520 | log_message.stream() << va_arg(args, long); |
| 521 | break; |
| 522 | case LogArgType::kLongLong: |
| 523 | log_message.stream() << va_arg(args, long long); |
| 524 | break; |
| 525 | case LogArgType::kUInt: |
| 526 | log_message.stream() << va_arg(args, unsigned); |
| 527 | break; |
| 528 | case LogArgType::kULong: |
| 529 | log_message.stream() << va_arg(args, unsigned long); |
| 530 | break; |
| 531 | case LogArgType::kULongLong: |
| 532 | log_message.stream() << va_arg(args, unsigned long long); |
| 533 | break; |
| 534 | case LogArgType::kDouble: |
| 535 | log_message.stream() << va_arg(args, double); |
| 536 | break; |
| 537 | case LogArgType::kLongDouble: |
| 538 | log_message.stream() << va_arg(args, long double); |
| 539 | break; |
| 540 | case LogArgType::kCharP: { |
| 541 | const char* s = va_arg(args, const char*); |
| 542 | log_message.stream() << (s ? s : "(null)"); |
| 543 | break; |
| 544 | } |
| 545 | case LogArgType::kStdString: |
| 546 | log_message.stream() << *va_arg(args, const std::string*); |
| 547 | break; |
| 548 | case LogArgType::kStringView: |
| 549 | log_message.stream() << *va_arg(args, const absl::string_view*); |
| 550 | break; |
| 551 | case LogArgType::kVoidP: |
| 552 | log_message.stream() << rtc::ToHex( |
| 553 | reinterpret_cast<uintptr_t>(va_arg(args, const void*))); |
| 554 | break; |
| 555 | default: |
| 556 | RTC_NOTREACHED(); |
| 557 | va_end(args); |
| 558 | return; |
| 559 | } |
| 560 | } |
| 561 |
| 562 | va_end(args); |
| 563 | } |
| 564 |
| 565 | } // namespace webrtc_logging_impl |
| 566 | } // namespace rtc |
| 567 | #endif |
| 568 |
| 569 | namespace rtc { |
| 570 | // Inefficient default implementation, override is recommended. |
| 571 | void LogSink::OnLogMessage(const std::string& msg, |
| 572 | LoggingSeverity severity, |
| 573 | const char* tag) { |
| 574 | OnLogMessage(tag + (": " + msg), severity); |
| 575 | } |
| 576 |
| 577 | void LogSink::OnLogMessage(const std::string& msg, |
| 578 | LoggingSeverity /* severity */) { |
| 579 | OnLogMessage(msg); |
| 580 | } |
| 581 | } // namespace rtc |
| 582 |