| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#ifndef RTC_BASE_LOGGING_H_ |
| 45 |
#define RTC_BASE_LOGGING_H_ |
| 46 |
|
| 47 |
#include <errno.h> |
| 48 |
|
| 49 |
#include <atomic> |
| 50 |
#include <sstream> |
| 51 |
#include <string> |
| 52 |
#include <utility> |
| 53 |
|
| 54 |
#include "absl/base/attributes.h" |
| 55 |
#include "absl/meta/type_traits.h" |
| 56 |
#include "absl/strings/string_view.h" |
| 57 |
#include "rtc_base/constructor_magic.h" |
| 58 |
#include "rtc_base/strings/string_builder.h" |
| 59 |
#include "rtc_base/system/inline.h" |
| 60 |
|
| 61 |
#if !defined(NDEBUG) || defined(DLOG_ALWAYS_ON) |
| 62 |
#define RTC_DLOG_IS_ON 1 |
| 63 |
#else |
| 64 |
#define RTC_DLOG_IS_ON 0 |
| 65 |
#endif |
| 66 |
|
| 67 |
#if defined(RTC_DISABLE_LOGGING) |
| 68 |
#define RTC_LOG_ENABLED() 0 |
| 69 |
#else |
| 70 |
#define RTC_LOG_ENABLED() 1 |
| 71 |
#endif |
| 72 |
|
| 73 |
namespace rtc { |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
enum LoggingSeverity { |
| 87 |
LS_VERBOSE, |
| 88 |
LS_INFO, |
| 89 |
LS_WARNING, |
| 90 |
LS_ERROR, |
| 91 |
LS_NONE, |
| 92 |
INFO = LS_INFO, |
| 93 |
WARNING = LS_WARNING, |
| 94 |
LERROR = LS_ERROR |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
enum LogErrorContext { |
| 99 |
ERRCTX_NONE, |
| 100 |
ERRCTX_ERRNO, |
| 101 |
ERRCTX_HRESULT, |
| 102 |
|
| 103 |
|
| 104 |
ERRCTX_EN = ERRCTX_ERRNO, |
| 105 |
ERRCTX_HR = ERRCTX_HRESULT, |
| 106 |
}; |
| 107 |
|
| 108 |
class LogMessage; |
| 109 |
|
| 110 |
class LogSink { |
| 111 |
public: |
| 112 |
LogSink() {} |
| 113 |
virtual ~LogSink() {} |
| 114 |
virtual void OnLogMessage(const std::string& msg, |
| 115 |
LoggingSeverity severity, |
| 116 |
const char* tag); |
| 117 |
virtual void OnLogMessage(const std::string& message, |
| 118 |
LoggingSeverity severity); |
| 119 |
virtual void OnLogMessage(const std::string& message) = 0; |
| 120 |
|
| 121 |
private: |
| 122 |
friend class ::rtc::LogMessage; |
| 123 |
#if RTC_LOG_ENABLED() |
| 124 |
|
| 125 |
LogSink* next_ = nullptr; |
| 126 |
LoggingSeverity min_severity_; |
| 127 |
#endif |
| 128 |
}; |
| 129 |
|
| 130 |
namespace webrtc_logging_impl { |
| 131 |
|
| 132 |
class LogMetadata { |
| 133 |
public: |
| 134 |
LogMetadata(const char* file, int line, LoggingSeverity severity) |
| 135 |
: file_(file), |
| 136 |
line_and_sev_(static_cast<uint32_t>(line) << 3 | severity) {} |
| 137 |
LogMetadata() = default; |
| 138 |
|
| 139 |
const char* File() const { return file_; } |
| 140 |
int Line() const { return line_and_sev_ >> 3; } |
| 141 |
LoggingSeverity Severity() const { |
| 142 |
return static_cast<LoggingSeverity>(line_and_sev_ & 0x7); |
| 143 |
} |
| 144 |
|
| 145 |
private: |
| 146 |
const char* file_; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
uint32_t line_and_sev_; |
| 153 |
}; |
| 154 |
static_assert(std::is_trivial<LogMetadata>::value, ""); |
| 155 |
|
| 156 |
struct LogMetadataErr { |
| 157 |
LogMetadata meta; |
| 158 |
LogErrorContext err_ctx; |
| 159 |
int err; |
| 160 |
}; |
| 161 |
|
| 162 |
#ifdef WEBRTC_ANDROID |
| 163 |
struct LogMetadataTag { |
| 164 |
LoggingSeverity severity; |
| 165 |
const char* tag; |
| 166 |
}; |
| 167 |
#endif |
| 168 |
|
| 169 |
enum class LogArgType : int8_t { |
| 170 |
kEnd = 0, |
| 171 |
kInt, |
| 172 |
kLong, |
| 173 |
kLongLong, |
| 174 |
kUInt, |
| 175 |
kULong, |
| 176 |
kULongLong, |
| 177 |
kDouble, |
| 178 |
kLongDouble, |
| 179 |
kCharP, |
| 180 |
kStdString, |
| 181 |
kStringView, |
| 182 |
kVoidP, |
| 183 |
kLogMetadata, |
| 184 |
kLogMetadataErr, |
| 185 |
#ifdef WEBRTC_ANDROID |
| 186 |
kLogMetadataTag, |
| 187 |
#endif |
| 188 |
}; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
template <LogArgType N, typename T> |
| 193 |
struct Val { |
| 194 |
static constexpr LogArgType Type() { return N; } |
| 195 |
T GetVal() const { return val; } |
| 196 |
T val; |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
struct ToStringVal { |
| 203 |
static constexpr LogArgType Type() { return LogArgType::kStdString; } |
| 204 |
const std::string* GetVal() const { return &val; } |
| 205 |
std::string val; |
| 206 |
}; |
| 207 |
|
| 208 |
inline Val<LogArgType::kInt, int> MakeVal(int x) { |
| 209 |
return {x}; |
| 210 |
} |
| 211 |
inline Val<LogArgType::kLong, long> MakeVal(long x) { |
| 212 |
return {x}; |
| 213 |
} |
| 214 |
inline Val<LogArgType::kLongLong, long long> MakeVal(long long x) { |
| 215 |
return {x}; |
| 216 |
} |
| 217 |
inline Val<LogArgType::kUInt, unsigned int> MakeVal(unsigned int x) { |
| 218 |
return {x}; |
| 219 |
} |
| 220 |
inline Val<LogArgType::kULong, unsigned long> MakeVal(unsigned long x) { |
| 221 |
return {x}; |
| 222 |
} |
| 223 |
inline Val<LogArgType::kULongLong, unsigned long long> MakeVal( |
| 224 |
unsigned long long x) { |
| 225 |
return {x}; |
| 226 |
} |
| 227 |
|
| 228 |
inline Val<LogArgType::kDouble, double> MakeVal(double x) { |
| 229 |
return {x}; |
| 230 |
} |
| 231 |
inline Val<LogArgType::kLongDouble, long double> MakeVal(long double x) { |
| 232 |
return {x}; |
| 233 |
} |
| 234 |
|
| 235 |
inline Val<LogArgType::kCharP, const char*> MakeVal(const char* x) { |
| 236 |
return {x}; |
| 237 |
} |
| 238 |
inline Val<LogArgType::kStdString, const std::string*> MakeVal( |
| 239 |
const std::string& x) { |
| 240 |
return {&x}; |
| 241 |
} |
| 242 |
inline Val<LogArgType::kStringView, const absl::string_view*> MakeVal( |
| 243 |
const absl::string_view& x) { |
| 244 |
return {&x}; |
| 245 |
} |
| 246 |
|
| 247 |
inline Val<LogArgType::kVoidP, const void*> MakeVal(const void* x) { |
| 248 |
return {x}; |
| 249 |
} |
| 250 |
|
| 251 |
inline Val<LogArgType::kLogMetadata, LogMetadata> MakeVal( |
| 252 |
const LogMetadata& x) { |
| 253 |
return {x}; |
| 254 |
} |
| 255 |
inline Val<LogArgType::kLogMetadataErr, LogMetadataErr> MakeVal( |
| 256 |
const LogMetadataErr& x) { |
| 257 |
return {x}; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
template <typename T, |
| 262 |
absl::enable_if_t<std::is_enum<T>::value && |
| 263 |
!std::is_arithmetic<T>::value>* = nullptr> |
| 264 |
inline decltype(MakeVal(std::declval<absl::underlying_type_t<T>>())) MakeVal( |
| 265 |
T x) { |
| 266 |
return {static_cast<absl::underlying_type_t<T>>(x)}; |
| 267 |
} |
| 268 |
|
| 269 |
#ifdef WEBRTC_ANDROID |
| 270 |
inline Val<LogArgType::kLogMetadataTag, LogMetadataTag> MakeVal( |
| 271 |
const LogMetadataTag& x) { |
| 272 |
return {x}; |
| 273 |
} |
| 274 |
#endif |
| 275 |
|
| 276 |
template <typename T, class = void> |
| 277 |
struct has_to_log_string : std::false_type {}; |
| 278 |
template <typename T> |
| 279 |
struct has_to_log_string<T, decltype(ToLogString(std::declval<T>()))> |
| 280 |
: std::true_type {}; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
template < |
| 286 |
typename T, |
| 287 |
typename T1 = absl::decay_t<T>, |
| 288 |
absl::enable_if_t<std::is_class<T1>::value && |
| 289 |
!std::is_same<T1, std::string>::value && |
| 290 |
!std::is_same<T1, LogMetadata>::value && |
| 291 |
!has_to_log_string<T1>::value && |
| 292 |
#ifdef WEBRTC_ANDROID |
| 293 |
!std::is_same<T1, LogMetadataTag>::value && |
| 294 |
#endif |
| 295 |
!std::is_same<T1, LogMetadataErr>::value>* = nullptr> |
| 296 |
ToStringVal MakeVal(const T& x) { |
| 297 |
std::ostringstream os; |
| 298 |
os << x; |
| 299 |
return {os.str()}; |
| 300 |
} |
| 301 |
|
| 302 |
template <typename T, absl::enable_if_t<has_to_log_string<T>::value>* = nullptr> |
| 303 |
ToStringVal MakeVal(const T& x) { |
| 304 |
return {ToLogString(x)}; |
| 305 |
} |
| 306 |
|
| 307 |
#if RTC_LOG_ENABLED() |
| 308 |
void Log(const LogArgType* fmt, ...); |
| 309 |
#else |
| 310 |
inline void Log(const LogArgType* fmt, ...) { |
| 311 |
|
| 312 |
} |
| 313 |
#endif |
| 314 |
|
| 315 |
|
| 316 |
template <typename... Ts> |
| 317 |
class LogStreamer; |
| 318 |
|
| 319 |
|
| 320 |
template <> |
| 321 |
class LogStreamer<> final { |
| 322 |
public: |
| 323 |
template <typename U, |
| 324 |
typename V = decltype(MakeVal(std::declval<U>())), |
| 325 |
absl::enable_if_t<std::is_arithmetic<U>::value || |
| 326 |
std::is_enum<U>::value>* = nullptr> |
| 327 |
RTC_FORCE_INLINE LogStreamer<V> operator<<(U arg) const { |
| 328 |
return LogStreamer<V>(MakeVal(arg), this); |
| 329 |
} |
| 330 |
|
| 331 |
template <typename U, |
| 332 |
typename V = decltype(MakeVal(std::declval<U>())), |
| 333 |
absl::enable_if_t<!std::is_arithmetic<U>::value && |
| 334 |
!std::is_enum<U>::value>* = nullptr> |
| 335 |
RTC_FORCE_INLINE LogStreamer<V> operator<<(const U& arg) const { |
| 336 |
return LogStreamer<V>(MakeVal(arg), this); |
| 337 |
} |
| 338 |
|
| 339 |
template <typename... Us> |
| 340 |
RTC_FORCE_INLINE static void Call(const Us&... args) { |
| 341 |
static constexpr LogArgType t[] = {Us::Type()..., LogArgType::kEnd}; |
| 342 |
Log(t, args.GetVal()...); |
| 343 |
} |
| 344 |
}; |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
template <typename T, typename... Ts> |
| 349 |
class LogStreamer<T, Ts...> final { |
| 350 |
public: |
| 351 |
RTC_FORCE_INLINE LogStreamer(T arg, const LogStreamer<Ts...>* prior) |
| 352 |
: arg_(arg), prior_(prior) {} |
| 353 |
|
| 354 |
template <typename U, |
| 355 |
typename V = decltype(MakeVal(std::declval<U>())), |
| 356 |
absl::enable_if_t<std::is_arithmetic<U>::value || |
| 357 |
std::is_enum<U>::value>* = nullptr> |
| 358 |
RTC_FORCE_INLINE LogStreamer<V, T, Ts...> operator<<(U arg) const { |
| 359 |
return LogStreamer<V, T, Ts...>(MakeVal(arg), this); |
| 360 |
} |
| 361 |
|
| 362 |
template <typename U, |
| 363 |
typename V = decltype(MakeVal(std::declval<U>())), |
| 364 |
absl::enable_if_t<!std::is_arithmetic<U>::value && |
| 365 |
!std::is_enum<U>::value>* = nullptr> |
| 366 |
RTC_FORCE_INLINE LogStreamer<V, T, Ts...> operator<<(const U& arg) const { |
| 367 |
return LogStreamer<V, T, Ts...>(MakeVal(arg), this); |
| 368 |
} |
| 369 |
|
| 370 |
template <typename... Us> |
| 371 |
RTC_FORCE_INLINE void Call(const Us&... args) const { |
| 372 |
prior_->Call(arg_, args...); |
| 373 |
} |
| 374 |
|
| 375 |
private: |
| 376 |
|
| 377 |
T arg_; |
| 378 |
|
| 379 |
|
| 380 |
const LogStreamer<Ts...>* prior_; |
| 381 |
}; |
| 382 |
|
| 383 |
class LogCall final { |
| 384 |
public: |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
template <typename... Ts> |
| 389 |
RTC_FORCE_INLINE bool operator&(const LogStreamer<Ts...>& streamer) { |
| 390 |
streamer.Call(); |
| 391 |
return true; |
| 392 |
} |
| 393 |
}; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
class LogMessageVoidify { |
| 399 |
public: |
| 400 |
LogMessageVoidify() = default; |
| 401 |
|
| 402 |
|
| 403 |
template <typename... Ts> |
| 404 |
void operator&(LogStreamer<Ts...>&& streamer) {} |
| 405 |
}; |
| 406 |
|
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
class LogMessage { |
| 414 |
public: |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
template <LoggingSeverity S> |
| 419 |
RTC_NO_INLINE LogMessage(const char* file, |
| 420 |
int line, |
| 421 |
std::integral_constant<LoggingSeverity, S>) |
| 422 |
: LogMessage(file, line, S) {} |
| 423 |
|
| 424 |
#if RTC_LOG_ENABLED() |
| 425 |
LogMessage(const char* file, int line, LoggingSeverity sev); |
| 426 |
LogMessage(const char* file, |
| 427 |
int line, |
| 428 |
LoggingSeverity sev, |
| 429 |
LogErrorContext err_ctx, |
| 430 |
int err); |
| 431 |
#if defined(WEBRTC_ANDROID) |
| 432 |
LogMessage(const char* file, int line, LoggingSeverity sev, const char* tag); |
| 433 |
#endif |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
ABSL_DEPRECATED("Use RTC_LOG macros instead of accessing this class directly") |
| 438 |
LogMessage(const char* file, |
| 439 |
int line, |
| 440 |
LoggingSeverity sev, |
| 441 |
const std::string& tag); |
| 442 |
~LogMessage(); |
| 443 |
|
| 444 |
void AddTag(const char* tag); |
| 445 |
rtc::StringBuilder& stream(); |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
static int64_t LogStartTime(); |
| 452 |
|
| 453 |
|
| 454 |
static uint32_t WallClockStartTime(); |
| 455 |
|
| 456 |
static void LogThreads(bool on = true); |
| 457 |
|
| 458 |
static void LogTimestamps(bool on = true); |
| 459 |
|
| 460 |
|
| 461 |
static void LogToDebug(LoggingSeverity min_sev); |
| 462 |
static LoggingSeverity GetLogToDebug(); |
| 463 |
|
| 464 |
static void SetLogToStderr(bool log_to_stderr); |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
static void AddLogToStream(LogSink* stream, LoggingSeverity min_sev); |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
static void RemoveLogToStream(LogSink* stream); |
| 476 |
|
| 477 |
|
| 478 |
static int GetLogToStream(LogSink* stream = nullptr); |
| 479 |
|
| 480 |
|
| 481 |
static int GetMinLogSeverity(); |
| 482 |
|
| 483 |
|
| 484 |
static void ConfigureLogging(const char* params); |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
static bool IsNoop(LoggingSeverity severity); |
| 490 |
|
| 491 |
|
| 492 |
template <LoggingSeverity S> |
| 493 |
RTC_NO_INLINE static bool IsNoop() { |
| 494 |
return IsNoop(S); |
| 495 |
} |
| 496 |
#else |
| 497 |
|
| 498 |
LogMessage(const char* file, int line, LoggingSeverity sev) {} |
| 499 |
LogMessage(const char* file, |
| 500 |
int line, |
| 501 |
LoggingSeverity sev, |
| 502 |
LogErrorContext err_ctx, |
| 503 |
int err) {} |
| 504 |
#if defined(WEBRTC_ANDROID) |
| 505 |
LogMessage(const char* file, int line, LoggingSeverity sev, const char* tag) { |
| 506 |
} |
| 507 |
#endif |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
ABSL_DEPRECATED("Use RTC_LOG macros instead of accessing this class directly") |
| 512 |
LogMessage(const char* file, |
| 513 |
int line, |
| 514 |
LoggingSeverity sev, |
| 515 |
const std::string& tag) {} |
| 516 |
~LogMessage() = default; |
| 517 |
|
| 518 |
inline void AddTag(const char* tag) {} |
| 519 |
inline rtc::StringBuilder& stream() { return print_stream_; } |
| 520 |
inline static int64_t LogStartTime() { return 0; } |
| 521 |
inline static uint32_t WallClockStartTime() { return 0; } |
| 522 |
inline static void LogThreads(bool on = true) {} |
| 523 |
inline static void LogTimestamps(bool on = true) {} |
| 524 |
inline static void LogToDebug(LoggingSeverity min_sev) {} |
| 525 |
inline static LoggingSeverity GetLogToDebug() { |
| 526 |
return LoggingSeverity::LS_INFO; |
| 527 |
} |
| 528 |
inline static void SetLogToStderr(bool log_to_stderr) {} |
| 529 |
inline static void AddLogToStream(LogSink* stream, LoggingSeverity min_sev) {} |
| 530 |
inline static void RemoveLogToStream(LogSink* stream) {} |
| 531 |
inline static int GetLogToStream(LogSink* stream = nullptr) { return 0; } |
| 532 |
inline static int GetMinLogSeverity() { return 0; } |
| 533 |
inline static void ConfigureLogging(const char* params) {} |
| 534 |
static constexpr bool IsNoop(LoggingSeverity severity) { return true; } |
| 535 |
template <LoggingSeverity S> |
| 536 |
static constexpr bool IsNoop() { |
| 537 |
return IsNoop(S); |
| 538 |
} |
| 539 |
#endif |
| 540 |
|
| 541 |
private: |
| 542 |
friend class LogMessageForTesting; |
| 543 |
|
| 544 |
#if RTC_LOG_ENABLED() |
| 545 |
|
| 546 |
static void UpdateMinLogSeverity(); |
| 547 |
|
| 548 |
|
| 549 |
#if defined(WEBRTC_ANDROID) |
| 550 |
static void OutputToDebug(const std::string& msg, |
| 551 |
LoggingSeverity severity, |
| 552 |
const char* tag); |
| 553 |
#else |
| 554 |
static void OutputToDebug(const std::string& msg, LoggingSeverity severity); |
| 555 |
#endif |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
void FinishPrintStream(); |
| 560 |
|
| 561 |
|
| 562 |
LoggingSeverity severity_; |
| 563 |
|
| 564 |
#if defined(WEBRTC_ANDROID) |
| 565 |
|
| 566 |
const char* tag_ = "libjingle"; |
| 567 |
#endif |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
std::string extra_; |
| 572 |
|
| 573 |
|
| 574 |
static LogSink* streams_; |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
static std::atomic<bool> streams_empty_; |
| 581 |
|
| 582 |
|
| 583 |
static bool thread_, timestamp_; |
| 584 |
|
| 585 |
|
| 586 |
static bool log_to_stderr_; |
| 587 |
#else |
| 588 |
|
| 589 |
inline static void UpdateMinLogSeverity() {} |
| 590 |
#if defined(WEBRTC_ANDROID) |
| 591 |
inline static void OutputToDebug(const std::string& msg, |
| 592 |
LoggingSeverity severity, |
| 593 |
const char* tag) {} |
| 594 |
#else |
| 595 |
inline static void OutputToDebug(const std::string& msg, |
| 596 |
LoggingSeverity severity) {} |
| 597 |
#endif |
| 598 |
inline void FinishPrintStream() {} |
| 599 |
#endif |
| 600 |
|
| 601 |
|
| 602 |
rtc::StringBuilder print_stream_; |
| 603 |
|
| 604 |
RTC_DISALLOW_COPY_AND_ASSIGN(LogMessage); |
| 605 |
}; |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
#define RTC_LOG_FILE_LINE(sev, file, line) \ |
| 612 |
::rtc::webrtc_logging_impl::LogCall() & \ |
| 613 |
::rtc::webrtc_logging_impl::LogStreamer<>() \ |
| 614 |
<< ::rtc::webrtc_logging_impl::LogMetadata(file, line, sev) |
| 615 |
|
| 616 |
#define RTC_LOG(sev) \ |
| 617 |
!rtc::LogMessage::IsNoop<::rtc::sev>() && \ |
| 618 |
RTC_LOG_FILE_LINE(::rtc::sev, __FILE__, __LINE__) |
| 619 |
|
| 620 |
|
| 621 |
#define RTC_LOG_V(sev) \ |
| 622 |
!rtc::LogMessage::IsNoop(sev) && RTC_LOG_FILE_LINE(sev, __FILE__, __LINE__) |
| 623 |
|
| 624 |
|
| 625 |
#if (defined(__GNUC__) && !defined(NDEBUG)) || defined(WANT_PRETTY_LOG_F) |
| 626 |
#define RTC_LOG_F(sev) RTC_LOG(sev) << __PRETTY_FUNCTION__ << ": " |
| 627 |
#define RTC_LOG_T_F(sev) \ |
| 628 |
RTC_LOG(sev) << this << ": " << __PRETTY_FUNCTION__ << ": " |
| 629 |
#else |
| 630 |
#define RTC_LOG_F(sev) RTC_LOG(sev) << __FUNCTION__ << ": " |
| 631 |
#define RTC_LOG_T_F(sev) RTC_LOG(sev) << this << ": " << __FUNCTION__ << ": " |
| 632 |
#endif |
| 633 |
|
| 634 |
#define RTC_LOG_CHECK_LEVEL(sev) ::rtc::LogCheckLevel(::rtc::sev) |
| 635 |
#define RTC_LOG_CHECK_LEVEL_V(sev) ::rtc::LogCheckLevel(sev) |
| 636 |
|
| 637 |
inline bool LogCheckLevel(LoggingSeverity sev) { |
| 638 |
return (LogMessage::GetMinLogSeverity() <= sev); |
| 639 |
} |
| 640 |
|
| 641 |
#define RTC_LOG_E(sev, ctx, err) \ |
| 642 |
!rtc::LogMessage::IsNoop<::rtc::sev>() && \ |
| 643 |
::rtc::webrtc_logging_impl::LogCall() & \ |
| 644 |
::rtc::webrtc_logging_impl::LogStreamer<>() \ |
| 645 |
<< ::rtc::webrtc_logging_impl::LogMetadataErr { \ |
| 646 |
{__FILE__, __LINE__, ::rtc::sev}, ::rtc::ERRCTX_##ctx, (err) \ |
| 647 |
} |
| 648 |
|
| 649 |
#define RTC_LOG_T(sev) RTC_LOG(sev) << this << ": " |
| 650 |
|
| 651 |
#define RTC_LOG_ERRNO_EX(sev, err) RTC_LOG_E(sev, ERRNO, err) |
| 652 |
#define RTC_LOG_ERRNO(sev) RTC_LOG_ERRNO_EX(sev, errno) |
| 653 |
|
| 654 |
#if defined(WEBRTC_WIN) |
| 655 |
#define RTC_LOG_GLE_EX(sev, err) RTC_LOG_E(sev, HRESULT, err) |
| 656 |
#define RTC_LOG_GLE(sev) RTC_LOG_GLE_EX(sev, static_cast<int>(GetLastError())) |
| 657 |
#define RTC_LOG_ERR_EX(sev, err) RTC_LOG_GLE_EX(sev, err) |
| 658 |
#define RTC_LOG_ERR(sev) RTC_LOG_GLE(sev) |
| 659 |
#elif defined(__native_client__) && __native_client__ |
| 660 |
#define RTC_LOG_ERR_EX(sev, err) RTC_LOG(sev) |
| 661 |
#define RTC_LOG_ERR(sev) RTC_LOG(sev) |
| 662 |
#elif defined(WEBRTC_POSIX) |
| 663 |
#define RTC_LOG_ERR_EX(sev, err) RTC_LOG_ERRNO_EX(sev, err) |
| 664 |
#define RTC_LOG_ERR(sev) RTC_LOG_ERRNO(sev) |
| 665 |
#endif |
| 666 |
|
| 667 |
#ifdef WEBRTC_ANDROID |
| 668 |
|
| 669 |
namespace webrtc_logging_impl { |
| 670 |
|
| 671 |
inline const char* AdaptString(const char* str) { |
| 672 |
return str; |
| 673 |
} |
| 674 |
inline const char* AdaptString(const std::string& str) { |
| 675 |
return str.c_str(); |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
#define RTC_LOG_TAG(sev, tag) \ |
| 680 |
!rtc::LogMessage::IsNoop(sev) && \ |
| 681 |
::rtc::webrtc_logging_impl::LogCall() & \ |
| 682 |
::rtc::webrtc_logging_impl::LogStreamer<>() \ |
| 683 |
<< ::rtc::webrtc_logging_impl::LogMetadataTag { \ |
| 684 |
sev, ::rtc::webrtc_logging_impl::AdaptString(tag) \ |
| 685 |
} |
| 686 |
|
| 687 |
#else |
| 688 |
|
| 689 |
|
| 690 |
#define RTC_LOG_TAG(sev, tag) RTC_LOG_V(sev) |
| 691 |
|
| 692 |
#endif |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
#if RTC_DLOG_IS_ON |
| 697 |
#define RTC_DLOG(sev) RTC_LOG(sev) |
| 698 |
#define RTC_DLOG_V(sev) RTC_LOG_V(sev) |
| 699 |
#define RTC_DLOG_F(sev) RTC_LOG_F(sev) |
| 700 |
#else |
| 701 |
#define RTC_DLOG_EAT_STREAM_PARAMS() \ |
| 702 |
while (false) \ |
| 703 |
::rtc::webrtc_logging_impl::LogMessageVoidify() & \ |
| 704 |
(::rtc::webrtc_logging_impl::LogStreamer<>()) |
| 705 |
#define RTC_DLOG(sev) RTC_DLOG_EAT_STREAM_PARAMS() |
| 706 |
#define RTC_DLOG_V(sev) RTC_DLOG_EAT_STREAM_PARAMS() |
| 707 |
#define RTC_DLOG_F(sev) RTC_DLOG_EAT_STREAM_PARAMS() |
| 708 |
#endif |
| 709 |
|
| 710 |
} |
| 711 |
|
| 712 |
#endif |