• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "base/logging.h"
9 #include "util/build_config.h"
10 
11 #if defined(OS_IOS)
12 #include <MacTypes.h>
13 #else
14 #include <libkern/OSTypes.h>
15 #endif
16 
17 // Use the OSSTATUS_LOG family to log messages related to errors in Mac OS X
18 // system routines that report status via an OSStatus or OSErr value. It is
19 // similar to the PLOG family which operates on errno, but because there is no
20 // global (or thread-local) OSStatus or OSErr value, the specific error must
21 // be supplied as an argument to the OSSTATUS_LOG macro. The message logged
22 // will contain the symbolic constant name corresponding to the status value,
23 // along with the value itself.
24 //
25 // OSErr is just an older 16-bit form of the newer 32-bit OSStatus. Despite
26 // the name, OSSTATUS_LOG can be used equally well for OSStatus and OSErr.
27 
28 namespace logging {
29 
30 // Returns a UTF8 description from an OS X Status error.
31 std::string DescriptionFromOSStatus(OSStatus err);
32 
33 class OSStatusLogMessage : public logging::LogMessage {
34  public:
35   OSStatusLogMessage(const char* file_path,
36                      int line,
37                      LogSeverity severity,
38                      OSStatus status);
39   ~OSStatusLogMessage();
40 
41  private:
42   OSStatus status_;
43 
44   OSStatusLogMessage(const OSStatusLogMessage&) = delete;
45   OSStatusLogMessage& operator=(const OSStatusLogMessage&) = delete;
46 };
47 
48 }  // namespace logging
49 
50 #define OSSTATUS_LOG_STREAM(severity, status) \
51   COMPACT_GOOGLE_LOG_EX_##severity(OSStatusLogMessage, status).stream()
52 
53 #define OSSTATUS_LOG(severity, status) \
54   LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), LOG_IS_ON(severity))
55 #define OSSTATUS_LOG_IF(severity, condition, status) \
56   LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
57               LOG_IS_ON(severity) && (condition))
58 
59 #define OSSTATUS_CHECK(condition, status)                       \
60   LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), !(condition)) \
61       << "Check failed: " #condition << ". "
62 
63 #define OSSTATUS_DLOG(severity, status) \
64   LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), DLOG_IS_ON(severity))
65 #define OSSTATUS_DLOG_IF(severity, condition, status) \
66   LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status),  \
67               DLOG_IS_ON(severity) && (condition))
68 
69 #define OSSTATUS_DCHECK(condition, status)        \
70   LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), \
71               DCHECK_IS_ON() && !(condition))     \
72       << "Check failed: " #condition << ". "
73 
74 #endif  // BASE_MAC_MAC_LOGGING_H_
75