Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: base/logging.h

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/icu_util.cc ('k') | base/logging_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cassert> 8 #include <cassert>
9 #include <string> 9 #include <string>
10 #include <cstring> 10 #include <cstring>
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) 553 #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2)
554 #define CHECK_IMPLIES(val1, val2) CHECK(!(val1) || (val2)) 554 #define CHECK_IMPLIES(val1, val2) CHECK(!(val1) || (val2))
555 555
556 #if defined(NDEBUG) 556 #if defined(NDEBUG)
557 #define ENABLE_DLOG 0 557 #define ENABLE_DLOG 0
558 #else 558 #else
559 #define ENABLE_DLOG 1 559 #define ENABLE_DLOG 1
560 #endif 560 #endif
561 561
562 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 562 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
563 #define DCHECK_IS_ON 0 563 #define DCHECK_IS_ON() 0
564 #else 564 #else
565 #define DCHECK_IS_ON 1 565 #define DCHECK_IS_ON() 1
566 #endif 566 #endif
567 567
568 // Definitions for DLOG et al. 568 // Definitions for DLOG et al.
569 569
570 #if ENABLE_DLOG 570 #if ENABLE_DLOG
571 571
572 #define DLOG_IS_ON(severity) LOG_IS_ON(severity) 572 #define DLOG_IS_ON(severity) LOG_IS_ON(severity)
573 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) 573 #define DLOG_IF(severity, condition) LOG_IF(severity, condition)
574 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) 574 #define DLOG_ASSERT(condition) LOG_ASSERT(condition)
575 #define DPLOG_IF(severity, condition) PLOG_IF(severity, condition) 575 #define DPLOG_IF(severity, condition) PLOG_IF(severity, condition)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 609
610 #define DPLOG(severity) \ 610 #define DPLOG(severity) \
611 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) 611 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))
612 612
613 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) 613 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
614 614
615 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) 615 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
616 616
617 // Definitions for DCHECK et al. 617 // Definitions for DCHECK et al.
618 618
619 #if DCHECK_IS_ON 619 #if DCHECK_IS_ON()
620 620
621 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ 621 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \
622 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) 622 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__)
623 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL 623 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL
624 const LogSeverity LOG_DCHECK = LOG_FATAL; 624 const LogSeverity LOG_DCHECK = LOG_FATAL;
625 625
626 #else // DCHECK_IS_ON 626 #else // DCHECK_IS_ON()
627 627
628 // These are just dummy values. 628 // These are just dummy values.
629 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ 629 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \
630 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) 630 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__)
631 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO 631 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO
632 const LogSeverity LOG_DCHECK = LOG_INFO; 632 const LogSeverity LOG_DCHECK = LOG_INFO;
633 633
634 #endif // DCHECK_IS_ON 634 #endif // DCHECK_IS_ON()
635 635
636 // DCHECK et al. make sure to reference |condition| regardless of 636 // DCHECK et al. make sure to reference |condition| regardless of
637 // whether DCHECKs are enabled; this is so that we don't get unused 637 // whether DCHECKs are enabled; this is so that we don't get unused
638 // variable warnings if the only use of a variable is in a DCHECK. 638 // variable warnings if the only use of a variable is in a DCHECK.
639 // This behavior is different from DLOG_IF et al. 639 // This behavior is different from DLOG_IF et al.
640 640
641 #if defined(_PREFAST_) && defined(OS_WIN) 641 #if defined(_PREFAST_) && defined(OS_WIN)
642 // See comments on the previous use of __analysis_assume. 642 // See comments on the previous use of __analysis_assume.
643 643
644 #define DCHECK(condition) \ 644 #define DCHECK(condition) \
645 __analysis_assume(!!(condition)), \ 645 __analysis_assume(!!(condition)), \
646 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ 646 LAZY_STREAM(LOG_STREAM(DCHECK), false) \
647 << "Check failed: " #condition ". " 647 << "Check failed: " #condition ". "
648 648
649 #define DPCHECK(condition) \ 649 #define DPCHECK(condition) \
650 __analysis_assume(!!(condition)), \ 650 __analysis_assume(!!(condition)), \
651 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ 651 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
652 << "Check failed: " #condition ". " 652 << "Check failed: " #condition ". "
653 653
654 #else // _PREFAST_ 654 #else // _PREFAST_
655 655
656 #define DCHECK(condition) \ 656 #define DCHECK(condition) \
657 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON ? !(condition) : false) \ 657 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
658 << "Check failed: " #condition ". " 658 << "Check failed: " #condition ". "
659 659
660 #define DPCHECK(condition) \ 660 #define DPCHECK(condition) \
661 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON ? !(condition) : false) \ 661 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
662 << "Check failed: " #condition ". " 662 << "Check failed: " #condition ". "
663 663
664 #endif // _PREFAST_ 664 #endif // _PREFAST_
665 665
666 // Helper macro for binary operators. 666 // Helper macro for binary operators.
667 // Don't use this macro directly in your code, use DCHECK_EQ et al below. 667 // Don't use this macro directly in your code, use DCHECK_EQ et al below.
668 #define DCHECK_OP(name, op, val1, val2) \ 668 #define DCHECK_OP(name, op, val1, val2) \
669 if (DCHECK_IS_ON) \ 669 if (DCHECK_IS_ON()) \
670 if (std::string* _result = \ 670 if (std::string* _result = logging::Check##name##Impl( \
671 logging::Check##name##Impl((val1), (val2), \ 671 (val1), (val2), #val1 " " #op " " #val2)) \
672 #val1 " " #op " " #val2)) \ 672 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, _result) \
673 logging::LogMessage( \ 673 .stream()
674 __FILE__, __LINE__, ::logging::LOG_DCHECK, \
675 _result).stream()
676 674
677 // Equality/Inequality checks - compare two values, and log a 675 // Equality/Inequality checks - compare two values, and log a
678 // LOG_DCHECK message including the two values when the result is not 676 // LOG_DCHECK message including the two values when the result is not
679 // as expected. The values must have operator<<(ostream, ...) 677 // as expected. The values must have operator<<(ostream, ...)
680 // defined. 678 // defined.
681 // 679 //
682 // You may append to the error message like so: 680 // You may append to the error message like so:
683 // DCHECK_NE(1, 2) << ": The world must be ending!"; 681 // DCHECK_NE(1, 2) << ": The world must be ending!";
684 // 682 //
685 // We are very careful to ensure that each argument is evaluated exactly 683 // We are very careful to ensure that each argument is evaluated exactly
686 // once, and that anything which is legal to pass as a function argument is 684 // once, and that anything which is legal to pass as a function argument is
687 // legal here. In particular, the arguments may be temporary expressions 685 // legal here. In particular, the arguments may be temporary expressions
688 // which will end up being destroyed at the end of the apparent statement, 686 // which will end up being destroyed at the end of the apparent statement,
689 // for example: 687 // for example:
690 // DCHECK_EQ(string("abc")[1], 'b'); 688 // DCHECK_EQ(string("abc")[1], 'b');
691 // 689 //
692 // WARNING: These may not compile correctly if one of the arguments is a pointer 690 // WARNING: These may not compile correctly if one of the arguments is a pointer
693 // and the other is NULL. To work around this, simply static_cast NULL to the 691 // and the other is NULL. To work around this, simply static_cast NULL to the
694 // type of the desired pointer. 692 // type of the desired pointer.
695 693
696 #define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2) 694 #define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2)
697 #define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2) 695 #define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2)
698 #define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2) 696 #define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2)
699 #define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2) 697 #define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2)
700 #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) 698 #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2)
701 #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) 699 #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2)
702 #define DCHECK_IMPLIES(val1, val2) DCHECK(!(val1) || (val2)) 700 #define DCHECK_IMPLIES(val1, val2) DCHECK(!(val1) || (val2))
703 701
704 #if !DCHECK_IS_ON && defined(OS_CHROMEOS) 702 #if !DCHECK_IS_ON() && defined(OS_CHROMEOS)
705 #define NOTREACHED() LOG(ERROR) << "NOTREACHED() hit in " << \ 703 #define NOTREACHED() LOG(ERROR) << "NOTREACHED() hit in " << \
706 __FUNCTION__ << ". " 704 __FUNCTION__ << ". "
707 #else 705 #else
708 #define NOTREACHED() DCHECK(false) 706 #define NOTREACHED() DCHECK(false)
709 #endif 707 #endif
710 708
711 // Redefine the standard assert to use our nice log files 709 // Redefine the standard assert to use our nice log files
712 #undef assert 710 #undef assert
713 #define assert(x) DLOG_ASSERT(x) 711 #define assert(x) DLOG_ASSERT(x)
714 712
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 #elif NOTIMPLEMENTED_POLICY == 5 926 #elif NOTIMPLEMENTED_POLICY == 5
929 #define NOTIMPLEMENTED() do {\ 927 #define NOTIMPLEMENTED() do {\
930 static bool logged_once = false;\ 928 static bool logged_once = false;\
931 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 929 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
932 logged_once = true;\ 930 logged_once = true;\
933 } while(0);\ 931 } while(0);\
934 EAT_STREAM_PARAMETERS 932 EAT_STREAM_PARAMETERS
935 #endif 933 #endif
936 934
937 #endif // BASE_LOGGING_H_ 935 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « base/i18n/icu_util.cc ('k') | base/logging_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698