Chromium Code Reviews| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 // (e.g., ::operator<<(ostream&, string&): it turns out that it's | 366 // (e.g., ::operator<<(ostream&, string&): it turns out that it's |
| 367 // impossible to stream something like a string directly to an unnamed | 367 // impossible to stream something like a string directly to an unnamed |
| 368 // ostream. We employ a neat hack by calling the stream() member | 368 // ostream. We employ a neat hack by calling the stream() member |
| 369 // function of LogMessage which seems to avoid the problem. | 369 // function of LogMessage which seems to avoid the problem. |
| 370 #define LOG_STREAM(severity) COMPACT_GOOGLE_LOG_ ## severity.stream() | 370 #define LOG_STREAM(severity) COMPACT_GOOGLE_LOG_ ## severity.stream() |
| 371 | 371 |
| 372 #define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity)) | 372 #define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity)) |
| 373 #define LOG_IF(severity, condition) \ | 373 #define LOG_IF(severity, condition) \ |
| 374 LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) | 374 LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) |
| 375 | 375 |
| 376 // Like LOG(...), but accepts an expression for the severity value, which may | |
| 377 // vary at runtime. | |
| 378 #define LOG_AT_LEVEL(severity) \ | |
|
danakj
2016/01/19 21:10:19
I like this better than the method, yah. But I don
| |
| 379 LAZY_STREAM(::logging::LogMessage(__FILE__, __LINE__, (severity)).stream(), \ | |
| 380 ::logging::ShouldCreateLogMessage(severity)) | |
| 381 | |
| 376 #define SYSLOG(severity) LOG(severity) | 382 #define SYSLOG(severity) LOG(severity) |
| 377 #define SYSLOG_IF(severity, condition) LOG_IF(severity, condition) | 383 #define SYSLOG_IF(severity, condition) LOG_IF(severity, condition) |
| 378 | 384 |
| 379 // The VLOG macros log with negative verbosities. | 385 // The VLOG macros log with negative verbosities. |
| 380 #define VLOG_STREAM(verbose_level) \ | 386 #define VLOG_STREAM(verbose_level) \ |
| 381 logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream() | 387 logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream() |
| 382 | 388 |
| 383 #define VLOG(verbose_level) \ | 389 #define VLOG(verbose_level) \ |
| 384 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) | 390 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) |
| 385 | 391 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 protected: | 806 protected: |
| 801 unsigned long last_error_; | 807 unsigned long last_error_; |
| 802 }; | 808 }; |
| 803 | 809 |
| 804 SaveLastError last_error_; | 810 SaveLastError last_error_; |
| 805 #endif | 811 #endif |
| 806 | 812 |
| 807 DISALLOW_COPY_AND_ASSIGN(LogMessage); | 813 DISALLOW_COPY_AND_ASSIGN(LogMessage); |
| 808 }; | 814 }; |
| 809 | 815 |
| 810 // A non-macro interface to the log facility; (useful | |
| 811 // when the logging level is not a compile-time constant). | |
| 812 inline void LogAtLevel(int log_level, const std::string& msg) { | |
| 813 LogMessage(__FILE__, __LINE__, log_level).stream() << msg; | |
| 814 } | |
| 815 | |
| 816 // This class is used to explicitly ignore values in the conditional | 816 // This class is used to explicitly ignore values in the conditional |
| 817 // logging macros. This avoids compiler warnings like "value computed | 817 // logging macros. This avoids compiler warnings like "value computed |
| 818 // is not used" and "statement has no effect". | 818 // is not used" and "statement has no effect". |
| 819 class LogMessageVoidify { | 819 class LogMessageVoidify { |
| 820 public: | 820 public: |
| 821 LogMessageVoidify() { } | 821 LogMessageVoidify() { } |
| 822 // This has to be an operator with a precedence lower than << but | 822 // This has to be an operator with a precedence lower than << but |
| 823 // higher than ?: | 823 // higher than ?: |
| 824 void operator&(std::ostream&) { } | 824 void operator&(std::ostream&) { } |
| 825 }; | 825 }; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 967 #elif NOTIMPLEMENTED_POLICY == 5 | 967 #elif NOTIMPLEMENTED_POLICY == 5 |
| 968 #define NOTIMPLEMENTED() do {\ | 968 #define NOTIMPLEMENTED() do {\ |
| 969 static bool logged_once = false;\ | 969 static bool logged_once = false;\ |
| 970 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 970 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 971 logged_once = true;\ | 971 logged_once = true;\ |
| 972 } while(0);\ | 972 } while(0);\ |
| 973 EAT_STREAM_PARAMETERS | 973 EAT_STREAM_PARAMETERS |
| 974 #endif | 974 #endif |
| 975 | 975 |
| 976 #endif // BASE_LOGGING_H_ | 976 #endif // BASE_LOGGING_H_ |
| OLD | NEW |