• 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 "base/macros.h"
10 #include "util/build_config.h"
11 
12 #if defined(OS_IOS)
13 #include <MacTypes.h>
14 #else
15 #include <libkern/OSTypes.h>
16 #endif
17 
18 // Use the OSSTATUS_LOG family to log messages related to errors in Mac OS X
19 // system routines that report status via an OSStatus or OSErr value. It is
20 // similar to the PLOG family which operates on errno, but because there is no
21 // global (or thread-local) OSStatus or OSErr value, the specific error must
22 // be supplied as an argument to the OSSTATUS_LOG macro. The message logged
23 // will contain the symbolic constant name corresponding to the status value,
24 // along with the value itself.
25 //
26 // OSErr is just an older 16-bit form of the newer 32-bit OSStatus. Despite
27 // the name, OSSTATUS_LOG can be used equally well for OSStatus and OSErr.
28 
29 namespace logging {
30 
31 // Returns a UTF8 description from an OS X Status error.
32 std::string DescriptionFromOSStatus(OSStatus err);
33 
34 class OSStatusLogMessage : public logging::LogMessage {
35  public:
36   OSStatusLogMessage(const char* file_path,
37                      int line,
38                      LogSeverity severity,
39                      OSStatus status);
40   ~OSStatusLogMessage();
41 
42  private:
43   OSStatus status_;
44 
45   DISALLOW_COPY_AND_ASSIGN(OSStatusLogMessage);
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