| 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 <cassert> | 8 #include <cassert> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <cstring> | 10 #include <cstring> |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 VLOG_IS_ON(verbose_level) && (condition)) | 419 VLOG_IS_ON(verbose_level) && (condition)) |
| 420 | 420 |
| 421 // TODO(akalin): Add more VLOG variants, e.g. VPLOG. | 421 // TODO(akalin): Add more VLOG variants, e.g. VPLOG. |
| 422 | 422 |
| 423 #define LOG_ASSERT(condition) \ | 423 #define LOG_ASSERT(condition) \ |
| 424 LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". " | 424 LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". " |
| 425 #define SYSLOG_ASSERT(condition) \ | 425 #define SYSLOG_ASSERT(condition) \ |
| 426 SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". " | 426 SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". " |
| 427 | 427 |
| 428 #if defined(OS_WIN) | 428 #if defined(OS_WIN) |
| 429 #define LOG_GETLASTERROR_STREAM(severity) \ | 429 #define PLOG_STREAM(severity) \ |
| 430 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \ | 430 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \ |
| 431 ::logging::GetLastSystemErrorCode()).stream() | 431 ::logging::GetLastSystemErrorCode()).stream() |
| 432 #define LOG_GETLASTERROR(severity) \ | |
| 433 LAZY_STREAM(LOG_GETLASTERROR_STREAM(severity), LOG_IS_ON(severity)) | |
| 434 #define LOG_GETLASTERROR_MODULE_STREAM(severity, module) \ | |
| 435 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \ | |
| 436 ::logging::GetLastSystemErrorCode(), module).stream() | |
| 437 #define LOG_GETLASTERROR_MODULE(severity, module) \ | |
| 438 LAZY_STREAM(LOG_GETLASTERROR_STREAM(severity, module), \ | |
| 439 LOG_IS_ON(severity)) | |
| 440 // PLOG_STREAM is used by PLOG, which is the usual error logging macro | |
| 441 // for each platform. | |
| 442 #define PLOG_STREAM(severity) LOG_GETLASTERROR_STREAM(severity) | |
| 443 #elif defined(OS_POSIX) | 432 #elif defined(OS_POSIX) |
| 444 #define LOG_ERRNO_STREAM(severity) \ | 433 #define PLOG_STREAM(severity) \ |
| 445 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \ | 434 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \ |
| 446 ::logging::GetLastSystemErrorCode()).stream() | 435 ::logging::GetLastSystemErrorCode()).stream() |
| 447 #define LOG_ERRNO(severity) \ | |
| 448 LAZY_STREAM(LOG_ERRNO_STREAM(severity), LOG_IS_ON(severity)) | |
| 449 // PLOG_STREAM is used by PLOG, which is the usual error logging macro | |
| 450 // for each platform. | |
| 451 #define PLOG_STREAM(severity) LOG_ERRNO_STREAM(severity) | |
| 452 #endif | 436 #endif |
| 453 | 437 |
| 454 #define PLOG(severity) \ | 438 #define PLOG(severity) \ |
| 455 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity)) | 439 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity)) |
| 456 | 440 |
| 457 #define PLOG_IF(severity, condition) \ | 441 #define PLOG_IF(severity, condition) \ |
| 458 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) | 442 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) |
| 459 | 443 |
| 460 // The actual stream used isn't important. | 444 // The actual stream used isn't important. |
| 461 #define EAT_STREAM_PARAMETERS \ | 445 #define EAT_STREAM_PARAMETERS \ |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 // #endif | 599 // #endif |
| 616 // | 600 // |
| 617 // We tie its state to ENABLE_DLOG. | 601 // We tie its state to ENABLE_DLOG. |
| 618 enum { DEBUG_MODE = ENABLE_DLOG }; | 602 enum { DEBUG_MODE = ENABLE_DLOG }; |
| 619 | 603 |
| 620 #undef ENABLE_DLOG | 604 #undef ENABLE_DLOG |
| 621 | 605 |
| 622 #define DLOG(severity) \ | 606 #define DLOG(severity) \ |
| 623 LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity)) | 607 LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity)) |
| 624 | 608 |
| 625 #if defined(OS_WIN) | |
| 626 #define DLOG_GETLASTERROR(severity) \ | |
| 627 LAZY_STREAM(LOG_GETLASTERROR_STREAM(severity), DLOG_IS_ON(severity)) | |
| 628 #define DLOG_GETLASTERROR_MODULE(severity, module) \ | |
| 629 LAZY_STREAM(LOG_GETLASTERROR_STREAM(severity, module), \ | |
| 630 DLOG_IS_ON(severity)) | |
| 631 #elif defined(OS_POSIX) | |
| 632 #define DLOG_ERRNO(severity) \ | |
| 633 LAZY_STREAM(LOG_ERRNO_STREAM(severity), DLOG_IS_ON(severity)) | |
| 634 #endif | |
| 635 | |
| 636 #define DPLOG(severity) \ | 609 #define DPLOG(severity) \ |
| 637 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) | 610 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) |
| 638 | 611 |
| 639 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 612 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
| 640 | 613 |
| 641 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 614 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
| 642 | 615 |
| 616 // TODO(vitalybuka): following should be removed and replaced with PLOG. |
| 617 #if defined(OS_WIN) |
| 618 #define LOG_GETLASTERROR(severity) PLOG(severity) |
| 619 #define DLOG_GETLASTERROR(severity) DPLOG(severity) |
| 620 #elif defined(OS_POSIX) |
| 621 #define LOG_ERRNO(severity) PLOG(severity) |
| 622 #define DLOG_ERRNO(severity) DPLOG(severity) |
| 623 #endif |
| 624 |
| 643 // Definitions for DCHECK et al. | 625 // Definitions for DCHECK et al. |
| 644 | 626 |
| 645 #if DCHECK_IS_ON | 627 #if DCHECK_IS_ON |
| 646 | 628 |
| 647 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 629 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
| 648 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) | 630 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) |
| 649 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL | 631 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL |
| 650 const LogSeverity LOG_DCHECK = LOG_FATAL; | 632 const LogSeverity LOG_DCHECK = LOG_FATAL; |
| 651 | 633 |
| 652 #else // DCHECK_IS_ON | 634 #else // DCHECK_IS_ON |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 798 |
| 817 #if defined(OS_WIN) | 799 #if defined(OS_WIN) |
| 818 typedef unsigned long SystemErrorCode; | 800 typedef unsigned long SystemErrorCode; |
| 819 #elif defined(OS_POSIX) | 801 #elif defined(OS_POSIX) |
| 820 typedef int SystemErrorCode; | 802 typedef int SystemErrorCode; |
| 821 #endif | 803 #endif |
| 822 | 804 |
| 823 // Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to | 805 // Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to |
| 824 // pull in windows.h just for GetLastError() and DWORD. | 806 // pull in windows.h just for GetLastError() and DWORD. |
| 825 BASE_EXPORT SystemErrorCode GetLastSystemErrorCode(); | 807 BASE_EXPORT SystemErrorCode GetLastSystemErrorCode(); |
| 808 BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code); |
| 826 | 809 |
| 827 #if defined(OS_WIN) | 810 #if defined(OS_WIN) |
| 828 // Appends a formatted system message of the GetLastError() type. | 811 // Appends a formatted system message of the GetLastError() type. |
| 829 class BASE_EXPORT Win32ErrorLogMessage { | 812 class BASE_EXPORT Win32ErrorLogMessage { |
| 830 public: | 813 public: |
| 831 Win32ErrorLogMessage(const char* file, | 814 Win32ErrorLogMessage(const char* file, |
| 832 int line, | 815 int line, |
| 833 LogSeverity severity, | 816 LogSeverity severity, |
| 834 SystemErrorCode err, | |
| 835 const char* module); | |
| 836 | |
| 837 Win32ErrorLogMessage(const char* file, | |
| 838 int line, | |
| 839 LogSeverity severity, | |
| 840 SystemErrorCode err); | 817 SystemErrorCode err); |
| 841 | 818 |
| 842 // Appends the error message before destructing the encapsulated class. | 819 // Appends the error message before destructing the encapsulated class. |
| 843 ~Win32ErrorLogMessage(); | 820 ~Win32ErrorLogMessage(); |
| 844 | 821 |
| 845 std::ostream& stream() { return log_message_.stream(); } | 822 std::ostream& stream() { return log_message_.stream(); } |
| 846 | 823 |
| 847 private: | 824 private: |
| 848 SystemErrorCode err_; | 825 SystemErrorCode err_; |
| 849 // Optional name of the module defining the error. | |
| 850 const char* module_; | |
| 851 LogMessage log_message_; | 826 LogMessage log_message_; |
| 852 | 827 |
| 853 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage); | 828 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage); |
| 854 }; | 829 }; |
| 855 #elif defined(OS_POSIX) | 830 #elif defined(OS_POSIX) |
| 856 // Appends a formatted system message of the errno type | 831 // Appends a formatted system message of the errno type |
| 857 class BASE_EXPORT ErrnoLogMessage { | 832 class BASE_EXPORT ErrnoLogMessage { |
| 858 public: | 833 public: |
| 859 ErrnoLogMessage(const char* file, | 834 ErrnoLogMessage(const char* file, |
| 860 int line, | 835 int line, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 #elif NOTIMPLEMENTED_POLICY == 5 | 926 #elif NOTIMPLEMENTED_POLICY == 5 |
| 952 #define NOTIMPLEMENTED() do {\ | 927 #define NOTIMPLEMENTED() do {\ |
| 953 static bool logged_once = false;\ | 928 static bool logged_once = false;\ |
| 954 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 929 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 955 logged_once = true;\ | 930 logged_once = true;\ |
| 956 } while(0);\ | 931 } while(0);\ |
| 957 EAT_STREAM_PARAMETERS | 932 EAT_STREAM_PARAMETERS |
| 958 #endif | 933 #endif |
| 959 | 934 |
| 960 #endif // BASE_LOGGING_H_ | 935 #endif // BASE_LOGGING_H_ |
| OLD | NEW |