OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_MAC_MAC_LOGGING_H_ |
| 6 #define BASE_MAC_MAC_LOGGING_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <libkern/OSTypes.h> |
| 10 |
| 11 #include "base/logging.h" |
| 12 |
| 13 // Use the OSSTATUS_LOG family to log messages related to errors in Mac OS X |
| 14 // system routines that report status via an OSStatus or OSErr value. It is |
| 15 // similar to the PLOG family which operates on errno, but because there is no |
| 16 // global (or thread-local) OSStatus or OSErr value, the specific error must |
| 17 // be supplied as an argument to the OSSTATUS_LOG macro. The message logged |
| 18 // will contain the symbolic constant name corresponding to the status value, |
| 19 // along with the value itself. |
| 20 // |
| 21 // OSErr is just an older 16-bit form of the newer 32-bit OSStatus. Despite |
| 22 // the name, OSSTATUS_LOG can be used equally well for OSStatus and OSErr. |
| 23 |
| 24 namespace logging { |
| 25 |
| 26 class OSStatusLogMessage : public logging::LogMessage { |
| 27 public: |
| 28 OSStatusLogMessage(const char* file_path, |
| 29 int line, |
| 30 LogSeverity severity, |
| 31 OSStatus status); |
| 32 ~OSStatusLogMessage(); |
| 33 |
| 34 private: |
| 35 OSStatus status_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(OSStatusLogMessage); |
| 38 }; |
| 39 |
| 40 } // namespace logging |
| 41 |
| 42 #define OSSTATUS_LOG_STREAM(severity, status) \ |
| 43 COMPACT_GOOGLE_LOG_EX_ ## severity(OSStatusLogMessage, status).stream() |
| 44 #define OSSTATUS_VLOG_STREAM(verbose_level, status) \ |
| 45 logging::OSStatusLogMessage(__FILE__, __LINE__, \ |
| 46 -verbose_level, status).stream() |
| 47 |
| 48 #define OSSTATUS_LOG(severity, status) \ |
| 49 LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), LOG_IS_ON(severity)) |
| 50 #define OSSTATUS_LOG_IF(severity, condition, status) \ |
| 51 LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \ |
| 52 LOG_IS_ON(severity) && (condition)) |
| 53 |
| 54 #define OSSTATUS_VLOG(verbose_level, status) \ |
| 55 LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \ |
| 56 VLOG_IS_ON(verbose_level)) |
| 57 #define OSSTATUS_VLOG_IF(verbose_level, condition, status) \ |
| 58 LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \ |
| 59 VLOG_IS_ON(verbose_level) && (condition)) |
| 60 |
| 61 #define OSSTATUS_CHECK(condition, status) \ |
| 62 LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), !(condition)) \ |
| 63 << "Check failed: " # condition << ". " |
| 64 |
| 65 #define OSSTATUS_DLOG(severity, status) \ |
| 66 LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), DLOG_IS_ON(severity)) |
| 67 #define OSSTATUS_DLOG_IF(severity, condition, status) \ |
| 68 LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \ |
| 69 DLOG_IS_ON(severity) && (condition)) |
| 70 |
| 71 #define OSSTATUS_DVLOG(verbose_level, status) \ |
| 72 LAZY_STREAM(OSSTATUS_VPLOG_STREAM(verbose_level, status), \ |
| 73 DVLOG_IS_ON(verbose_level)) |
| 74 #define OSSTATUS_DVLOG_IF(verbose_level, condition, status) \ |
| 75 LAZY_STREAM(OSSTATUS_VPLOG_STREAM(verbose_level, status) \ |
| 76 DVLOG_IS_ON(verbose_level) && (condition)) |
| 77 |
| 78 #define OSSTATUS_DCHECK(condition, status) \ |
| 79 LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), \ |
| 80 DCHECK_IS_ON() && !(condition)) \ |
| 81 << "Check failed: " # condition << ". " |
| 82 |
| 83 #endif // BASE_MAC_MAC_LOGGING_H_ |
OLD | NEW |