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 #ifndef BASE_LOGGING_H_ | 5 #ifndef BASE_LOGGING_H_ |
6 #define BASE_LOGGING_H_ | 6 #define BASE_LOGGING_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cassert> | 10 #include <cassert> |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 #ifdef NDEBUG | 302 #ifdef NDEBUG |
303 const LogSeverity LOG_DFATAL = LOG_ERROR; | 303 const LogSeverity LOG_DFATAL = LOG_ERROR; |
304 #else | 304 #else |
305 const LogSeverity LOG_DFATAL = LOG_FATAL; | 305 const LogSeverity LOG_DFATAL = LOG_FATAL; |
306 #endif | 306 #endif |
307 | 307 |
308 // A few definitions of macros that don't generate much code. These are used | 308 // A few definitions of macros that don't generate much code. These are used |
309 // by LOG() and LOG_IF, etc. Since these are used all over our code, it's | 309 // by LOG() and LOG_IF, etc. Since these are used all over our code, it's |
310 // better to have compact code for these operations. | 310 // better to have compact code for these operations. |
311 #define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \ | 311 #define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \ |
312 logging::ClassName(__FILE__, __LINE__, logging::LOG_INFO , ##__VA_ARGS__) | 312 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_INFO, ##__VA_ARGS__) |
313 #define COMPACT_GOOGLE_LOG_EX_WARNING(ClassName, ...) \ | 313 #define COMPACT_GOOGLE_LOG_EX_WARNING(ClassName, ...) \ |
314 logging::ClassName(__FILE__, __LINE__, logging::LOG_WARNING , ##__VA_ARGS__) | 314 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_WARNING, \ |
| 315 ##__VA_ARGS__) |
315 #define COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ...) \ | 316 #define COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ...) \ |
316 logging::ClassName(__FILE__, __LINE__, logging::LOG_ERROR , ##__VA_ARGS__) | 317 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_ERROR, ##__VA_ARGS__) |
317 #define COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ...) \ | 318 #define COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ...) \ |
318 logging::ClassName(__FILE__, __LINE__, logging::LOG_FATAL , ##__VA_ARGS__) | 319 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_FATAL, ##__VA_ARGS__) |
319 #define COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ...) \ | 320 #define COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ...) \ |
320 logging::ClassName(__FILE__, __LINE__, logging::LOG_DFATAL , ##__VA_ARGS__) | 321 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_DFATAL, ##__VA_ARGS__) |
321 | 322 |
322 #define COMPACT_GOOGLE_LOG_INFO \ | 323 #define COMPACT_GOOGLE_LOG_INFO \ |
323 COMPACT_GOOGLE_LOG_EX_INFO(LogMessage) | 324 COMPACT_GOOGLE_LOG_EX_INFO(LogMessage) |
324 #define COMPACT_GOOGLE_LOG_WARNING \ | 325 #define COMPACT_GOOGLE_LOG_WARNING \ |
325 COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage) | 326 COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage) |
326 #define COMPACT_GOOGLE_LOG_ERROR \ | 327 #define COMPACT_GOOGLE_LOG_ERROR \ |
327 COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage) | 328 COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage) |
328 #define COMPACT_GOOGLE_LOG_FATAL \ | 329 #define COMPACT_GOOGLE_LOG_FATAL \ |
329 COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage) | 330 COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage) |
330 #define COMPACT_GOOGLE_LOG_DFATAL \ | 331 #define COMPACT_GOOGLE_LOG_DFATAL \ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // ostream. We employ a neat hack by calling the stream() member | 372 // ostream. We employ a neat hack by calling the stream() member |
372 // function of LogMessage which seems to avoid the problem. | 373 // function of LogMessage which seems to avoid the problem. |
373 #define LOG_STREAM(severity) COMPACT_GOOGLE_LOG_ ## severity.stream() | 374 #define LOG_STREAM(severity) COMPACT_GOOGLE_LOG_ ## severity.stream() |
374 | 375 |
375 #define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity)) | 376 #define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity)) |
376 #define LOG_IF(severity, condition) \ | 377 #define LOG_IF(severity, condition) \ |
377 LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) | 378 LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) |
378 | 379 |
379 // The VLOG macros log with negative verbosities. | 380 // The VLOG macros log with negative verbosities. |
380 #define VLOG_STREAM(verbose_level) \ | 381 #define VLOG_STREAM(verbose_level) \ |
381 logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream() | 382 ::logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream() |
382 | 383 |
383 #define VLOG(verbose_level) \ | 384 #define VLOG(verbose_level) \ |
384 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) | 385 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) |
385 | 386 |
386 #define VLOG_IF(verbose_level, condition) \ | 387 #define VLOG_IF(verbose_level, condition) \ |
387 LAZY_STREAM(VLOG_STREAM(verbose_level), \ | 388 LAZY_STREAM(VLOG_STREAM(verbose_level), \ |
388 VLOG_IS_ON(verbose_level) && (condition)) | 389 VLOG_IS_ON(verbose_level) && (condition)) |
389 | 390 |
390 #if defined (OS_WIN) | 391 #if defined (OS_WIN) |
391 #define VPLOG_STREAM(verbose_level) \ | 392 #define VPLOG_STREAM(verbose_level) \ |
392 logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \ | 393 ::logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \ |
393 ::logging::GetLastSystemErrorCode()).stream() | 394 ::logging::GetLastSystemErrorCode()).stream() |
394 #elif defined(OS_POSIX) | 395 #elif defined(OS_POSIX) |
395 #define VPLOG_STREAM(verbose_level) \ | 396 #define VPLOG_STREAM(verbose_level) \ |
396 logging::ErrnoLogMessage(__FILE__, __LINE__, -verbose_level, \ | 397 ::logging::ErrnoLogMessage(__FILE__, __LINE__, -verbose_level, \ |
397 ::logging::GetLastSystemErrorCode()).stream() | 398 ::logging::GetLastSystemErrorCode()).stream() |
398 #endif | 399 #endif |
399 | 400 |
400 #define VPLOG(verbose_level) \ | 401 #define VPLOG(verbose_level) \ |
401 LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) | 402 LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) |
402 | 403 |
403 #define VPLOG_IF(verbose_level, condition) \ | 404 #define VPLOG_IF(verbose_level, condition) \ |
404 LAZY_STREAM(VPLOG_STREAM(verbose_level), \ | 405 LAZY_STREAM(VPLOG_STREAM(verbose_level), \ |
405 VLOG_IS_ON(verbose_level) && (condition)) | 406 VLOG_IS_ON(verbose_level) && (condition)) |
406 | 407 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 << "Check failed: " #condition ". " | 483 << "Check failed: " #condition ". " |
483 | 484 |
484 #define PCHECK(condition) \ | 485 #define PCHECK(condition) \ |
485 __analysis_assume(!!(condition)), \ | 486 __analysis_assume(!!(condition)), \ |
486 LAZY_STREAM(PLOG_STREAM(FATAL), false) \ | 487 LAZY_STREAM(PLOG_STREAM(FATAL), false) \ |
487 << "Check failed: " #condition ". " | 488 << "Check failed: " #condition ". " |
488 | 489 |
489 #else // _PREFAST_ | 490 #else // _PREFAST_ |
490 | 491 |
491 // Do as much work as possible out of line to reduce inline code size. | 492 // Do as much work as possible out of line to reduce inline code size. |
492 #define CHECK(condition) \ | 493 #define CHECK(condition) \ |
493 LAZY_STREAM(logging::LogMessage(__FILE__, __LINE__, #condition).stream(), \ | 494 LAZY_STREAM(::logging::LogMessage(__FILE__, __LINE__, #condition).stream(), \ |
494 !(condition)) | 495 !(condition)) |
495 | 496 |
496 #define PCHECK(condition) \ | 497 #define PCHECK(condition) \ |
497 LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ | 498 LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ |
498 << "Check failed: " #condition ". " | 499 << "Check failed: " #condition ". " |
499 | 500 |
500 #endif // _PREFAST_ | 501 #endif // _PREFAST_ |
501 | 502 |
502 // Helper macro for binary operators. | 503 // Helper macro for binary operators. |
503 // Don't use this macro directly in your code, use CHECK_EQ et al below. | 504 // Don't use this macro directly in your code, use CHECK_EQ et al below. |
504 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 505 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
505 // macro is used in an 'if' clause such as: | 506 // macro is used in an 'if' clause such as: |
506 // if (a == 1) | 507 // if (a == 1) |
507 // CHECK_EQ(2, a); | 508 // CHECK_EQ(2, a); |
508 #define CHECK_OP(name, op, val1, val2) \ | 509 #define CHECK_OP(name, op, val1, val2) \ |
509 switch (0) case 0: default: \ | 510 switch (0) case 0: default: \ |
510 if (logging::CheckOpResult true_if_passed = \ | 511 if (::logging::CheckOpResult true_if_passed = \ |
511 logging::Check##name##Impl((val1), (val2), \ | 512 ::logging::Check##name##Impl((val1), (val2), \ |
512 #val1 " " #op " " #val2)) \ | 513 #val1 " " #op " " #val2)) \ |
513 ; \ | 514 ; \ |
514 else \ | 515 else \ |
515 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() | 516 ::logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() |
516 | 517 |
517 #endif // !(OFFICIAL_BUILD && NDEBUG) | 518 #endif // !(OFFICIAL_BUILD && NDEBUG) |
518 | 519 |
519 // This formats a value for a failing CHECK_XX statement. Ordinarily, | 520 // This formats a value for a failing CHECK_XX statement. Ordinarily, |
520 // it uses the definition for operator<<, with a few special cases below. | 521 // it uses the definition for operator<<, with a few special cases below. |
521 template <typename T> | 522 template <typename T> |
522 inline typename std::enable_if< | 523 inline typename std::enable_if< |
523 base::internal::SupportsOstreamOperator<const T&>::value, | 524 base::internal::SupportsOstreamOperator<const T&>::value, |
524 void>::type | 525 void>::type |
525 MakeCheckOpValueString(std::ostream* os, const T& v) { | 526 MakeCheckOpValueString(std::ostream* os, const T& v) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 << "Check failed: " #condition ". " | 713 << "Check failed: " #condition ". " |
713 | 714 |
714 #endif // _PREFAST_ | 715 #endif // _PREFAST_ |
715 | 716 |
716 // Helper macro for binary operators. | 717 // Helper macro for binary operators. |
717 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 718 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
718 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 719 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
719 // macro is used in an 'if' clause such as: | 720 // macro is used in an 'if' clause such as: |
720 // if (a == 1) | 721 // if (a == 1) |
721 // DCHECK_EQ(2, a); | 722 // DCHECK_EQ(2, a); |
722 #define DCHECK_OP(name, op, val1, val2) \ | 723 #define DCHECK_OP(name, op, val1, val2) \ |
723 switch (0) case 0: default: \ | 724 switch (0) case 0: default: \ |
724 if (logging::CheckOpResult true_if_passed = \ | 725 if (::logging::CheckOpResult true_if_passed = \ |
725 DCHECK_IS_ON() ? \ | 726 DCHECK_IS_ON() ? \ |
726 logging::Check##name##Impl((val1), (val2), \ | 727 ::logging::Check##name##Impl((val1), (val2), \ |
727 #val1 " " #op " " #val2) : nullptr) \ | 728 #val1 " " #op " " #val2) : nullptr) \ |
728 ; \ | 729 ; \ |
729 else \ | 730 else \ |
730 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ | 731 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ |
731 true_if_passed.message()).stream() | 732 true_if_passed.message()).stream() |
732 | 733 |
733 // Equality/Inequality checks - compare two values, and log a | 734 // Equality/Inequality checks - compare two values, and log a |
734 // LOG_DCHECK message including the two values when the result is not | 735 // LOG_DCHECK message including the two values when the result is not |
735 // as expected. The values must have operator<<(ostream, ...) | 736 // as expected. The values must have operator<<(ostream, ...) |
736 // defined. | 737 // defined. |
737 // | 738 // |
738 // You may append to the error message like so: | 739 // You may append to the error message like so: |
739 // DCHECK_NE(1, 2) << ": The world must be ending!"; | 740 // DCHECK_NE(1, 2) << ": The world must be ending!"; |
740 // | 741 // |
741 // We are very careful to ensure that each argument is evaluated exactly | 742 // We are very careful to ensure that each argument is evaluated exactly |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 | 901 |
901 // Closes the log file explicitly if open. | 902 // Closes the log file explicitly if open. |
902 // NOTE: Since the log file is opened as necessary by the action of logging | 903 // NOTE: Since the log file is opened as necessary by the action of logging |
903 // statements, there's no guarantee that it will stay closed | 904 // statements, there's no guarantee that it will stay closed |
904 // after this call. | 905 // after this call. |
905 BASE_EXPORT void CloseLogFile(); | 906 BASE_EXPORT void CloseLogFile(); |
906 | 907 |
907 // Async signal safe logging mechanism. | 908 // Async signal safe logging mechanism. |
908 BASE_EXPORT void RawLog(int level, const char* message); | 909 BASE_EXPORT void RawLog(int level, const char* message); |
909 | 910 |
910 #define RAW_LOG(level, message) logging::RawLog(logging::LOG_ ## level, message) | 911 #define RAW_LOG(level, message) \ |
| 912 ::logging::RawLog(::logging::LOG_##level, message) |
911 | 913 |
912 #define RAW_CHECK(condition) \ | 914 #define RAW_CHECK(condition) \ |
913 do { \ | 915 do { \ |
914 if (!(condition)) \ | 916 if (!(condition)) \ |
915 logging::RawLog(logging::LOG_FATAL, "Check failed: " #condition "\n"); \ | 917 ::logging::RawLog(::logging::LOG_FATAL, \ |
| 918 "Check failed: " #condition "\n"); \ |
916 } while (0) | 919 } while (0) |
917 | 920 |
918 #if defined(OS_WIN) | 921 #if defined(OS_WIN) |
919 // Returns true if logging to file is enabled. | 922 // Returns true if logging to file is enabled. |
920 BASE_EXPORT bool IsLoggingToFileEnabled(); | 923 BASE_EXPORT bool IsLoggingToFileEnabled(); |
921 | 924 |
922 // Returns the default log file path. | 925 // Returns the default log file path. |
923 BASE_EXPORT std::wstring GetLogFileFullPath(); | 926 BASE_EXPORT std::wstring GetLogFileFullPath(); |
924 #endif | 927 #endif |
925 | 928 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 #elif NOTIMPLEMENTED_POLICY == 5 | 991 #elif NOTIMPLEMENTED_POLICY == 5 |
989 #define NOTIMPLEMENTED() do {\ | 992 #define NOTIMPLEMENTED() do {\ |
990 static bool logged_once = false;\ | 993 static bool logged_once = false;\ |
991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 994 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
992 logged_once = true;\ | 995 logged_once = true;\ |
993 } while(0);\ | 996 } while(0);\ |
994 EAT_STREAM_PARAMETERS | 997 EAT_STREAM_PARAMETERS |
995 #endif | 998 #endif |
996 | 999 |
997 #endif // BASE_LOGGING_H_ | 1000 #endif // BASE_LOGGING_H_ |
OLD | NEW |