summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 23:06:49 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 23:06:49 +0000
commit33b9820a5039e8a9925ddc0ebaced8f50112ce3b (patch)
treefc66820a0ea13d0160dfb3253028cb8a1d3b468f /base
parent1797640037e0127eb5f47bc60dc94b78a2b904b5 (diff)
downloadchromium_src-33b9820a5039e8a9925ddc0ebaced8f50112ce3b.zip
chromium_src-33b9820a5039e8a9925ddc0ebaced8f50112ce3b.tar.gz
chromium_src-33b9820a5039e8a9925ddc0ebaced8f50112ce3b.tar.bz2
Add OSSTATUS_LOG API.
Review URL: https://chromiumcodereview.appspot.com/9235084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119511 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi2
-rw-r--r--base/logging.h1
-rw-r--r--base/mac/foundation_util.mm5
-rw-r--r--base/mac/mac_logging.cc29
-rw-r--r--base/mac/mac_logging.h83
-rw-r--r--base/mac/mac_util.mm18
6 files changed, 126 insertions, 12 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 238dd75..2d10270 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -151,6 +151,8 @@
'mac/crash_logging.mm',
'mac/foundation_util.h',
'mac/foundation_util.mm',
+ 'mac/mac_logging.h',
+ 'mac/mac_logging.cc',
'mac/mac_util.h',
'mac/mac_util.mm',
'mac/objc_property_releaser.h',
diff --git a/base/logging.h b/base/logging.h
index df31955..e9faca3 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -438,7 +438,6 @@ const LogSeverity LOG_0 = LOG_ERROR;
// PLOG_STREAM is used by PLOG, which is the usual error logging macro
// for each platform.
#define PLOG_STREAM(severity) LOG_ERRNO_STREAM(severity)
-// TODO(tschmelcher): Should we add OSStatus logging for Mac?
#endif
#define PLOG(severity) \
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index 6feeaf4..8ab02ab 100644
--- a/base/mac/foundation_util.mm
+++ b/base/mac/foundation_util.mm
@@ -10,6 +10,7 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
+#include "base/mac/mac_logging.h"
#include "base/sys_string_conversions.h"
namespace base {
@@ -28,7 +29,7 @@ static bool UncachedAmIBundled() {
FSRef fsref;
OSStatus pbErr;
if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) {
- DLOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr;
+ OSSTATUS_DLOG(ERROR, pbErr) << "GetProcessBundleLocation failed";
return false;
}
@@ -36,7 +37,7 @@ static bool UncachedAmIBundled() {
OSErr fsErr;
if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
NULL, NULL, NULL)) != noErr) {
- DLOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr;
+ OSSTATUS_DLOG(ERROR, fsErr) << "FSGetCatalogInfo failed";
return false;
}
diff --git a/base/mac/mac_logging.cc b/base/mac/mac_logging.cc
new file mode 100644
index 0000000..353f092
--- /dev/null
+++ b/base/mac/mac_logging.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac/mac_logging.h"
+
+#include <CoreServices/CoreServices.h>
+
+#include <iomanip>
+
+namespace logging {
+
+OSStatusLogMessage::OSStatusLogMessage(const char* file_path,
+ int line,
+ LogSeverity severity,
+ OSStatus status)
+ : LogMessage(file_path, line, severity),
+ status_(status) {
+}
+
+OSStatusLogMessage::~OSStatusLogMessage() {
+ stream() << ": "
+ << GetMacOSStatusErrorString(status_)
+ << " ("
+ << status_
+ << ")";
+}
+
+} // namespace logging
diff --git a/base/mac/mac_logging.h b/base/mac/mac_logging.h
new file mode 100644
index 0000000..e2d0c52
--- /dev/null
+++ b/base/mac/mac_logging.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MAC_MAC_LOGGING_H_
+#define BASE_MAC_MAC_LOGGING_H_
+#pragma once
+
+#include <libkern/OSTypes.h>
+
+#include "base/logging.h"
+
+// Use the OSSTATUS_LOG family to log messages related to errors in Mac OS X
+// system routines that report status via an OSStatus or OSErr value. It is
+// similar to the PLOG family which operates on errno, but because there is no
+// global (or thread-local) OSStatus or OSErr value, the specific error must
+// be supplied as an argument to the OSSTATUS_LOG macro. The message logged
+// will contain the symbolic constant name corresponding to the status value,
+// along with the value itself.
+//
+// OSErr is just an older 16-bit form of the newer 32-bit OSStatus. Despite
+// the name, OSSTATUS_LOG can be used equally well for OSStatus and OSErr.
+
+namespace logging {
+
+class OSStatusLogMessage : public logging::LogMessage {
+ public:
+ OSStatusLogMessage(const char* file_path,
+ int line,
+ LogSeverity severity,
+ OSStatus status);
+ ~OSStatusLogMessage();
+
+ private:
+ OSStatus status_;
+
+ DISALLOW_COPY_AND_ASSIGN(OSStatusLogMessage);
+};
+
+} // namespace logging
+
+#define OSSTATUS_LOG_STREAM(severity, status) \
+ COMPACT_GOOGLE_LOG_EX_ ## severity(OSStatusLogMessage, status).stream()
+#define OSSTATUS_VLOG_STREAM(verbose_level, status) \
+ logging::OSStatusLogMessage(__FILE__, __LINE__, \
+ -verbose_level, status).stream()
+
+#define OSSTATUS_LOG(severity, status) \
+ LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), LOG_IS_ON(severity))
+#define OSSTATUS_LOG_IF(severity, condition, status) \
+ LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
+ LOG_IS_ON(severity) && (condition))
+
+#define OSSTATUS_VLOG(verbose_level, status) \
+ LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
+ VLOG_IS_ON(verbose_level))
+#define OSSTATUS_VLOG_IF(verbose_level, condition, status) \
+ LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
+ VLOG_IS_ON(verbose_level) && (condition))
+
+#define OSSTATUS_CHECK(condition, status) \
+ LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), !(condition)) \
+ << "Check failed: " # condition << ". "
+
+#define OSSTATUS_DLOG(severity, status) \
+ LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), DLOG_IS_ON(severity))
+#define OSSTATUS_DLOG_IF(severity, condition, status) \
+ LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
+ DLOG_IS_ON(severity) && (condition))
+
+#define OSSTATUS_DVLOG(verbose_level, status) \
+ LAZY_STREAM(OSSTATUS_VPLOG_STREAM(verbose_level, status), \
+ DVLOG_IS_ON(verbose_level))
+#define OSSTATUS_DVLOG_IF(verbose_level, condition, status) \
+ LAZY_STREAM(OSSTATUS_VPLOG_STREAM(verbose_level, status) \
+ DVLOG_IS_ON(verbose_level) && (condition))
+
+#define OSSTATUS_DCHECK(condition, status) \
+ LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), \
+ DCHECK_IS_ON() && !(condition)) \
+ << "Check failed: " # condition << ". "
+
+#endif // BASE_MAC_MAC_LOGGING_H_
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm
index 7c020e1..e73216e 100644
--- a/base/mac/mac_util.mm
+++ b/base/mac/mac_util.mm
@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
+#include "base/mac/mac_logging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_nsobject.h"
#include "base/string_number_conversions.h"
@@ -218,7 +219,7 @@ void ActivateProcess(pid_t pid) {
if (status == noErr) {
SetFrontProcess(&process);
} else {
- DLOG(WARNING) << "Unable to get process for pid " << pid;
+ OSSTATUS_DLOG(WARNING, status) << "Unable to get process for pid " << pid;
}
}
@@ -226,7 +227,7 @@ bool AmIForeground() {
ProcessSerialNumber foreground_psn = { 0 };
OSErr err = GetFrontProcess(&foreground_psn);
if (err != noErr) {
- DLOG(WARNING) << "GetFrontProcess: " << err;
+ OSSTATUS_DLOG(WARNING, err) << "GetFrontProcess";
return false;
}
@@ -235,7 +236,7 @@ bool AmIForeground() {
Boolean result = FALSE;
err = SameProcess(&foreground_psn, &my_psn, &result);
if (err != noErr) {
- DLOG(WARNING) << "SameProcess: " << err;
+ OSSTATUS_DLOG(WARNING, err) << "SameProcess";
return false;
}
@@ -256,11 +257,9 @@ bool SetFileBackupExclusion(const FilePath& file_path) {
OSStatus os_err =
CSBackupSetItemExcluded(base::mac::NSToCFCast(file_url), TRUE, FALSE);
if (os_err != noErr) {
- DLOG(WARNING) << "Failed to set backup exclusion for file '"
- << file_path.value().c_str() << "' with error "
- << os_err << " (" << GetMacOSStatusErrorString(os_err)
- << ": " << GetMacOSStatusCommentString(os_err)
- << "). Continuing.";
+ OSSTATUS_DLOG(WARNING, os_err)
+ << "Failed to set backup exclusion for file '"
+ << file_path.value().c_str() << "'";
}
return os_err == noErr;
}
@@ -351,7 +350,8 @@ void SetProcessName(CFStringRef process_name) {
ls_display_name_key,
process_name,
NULL /* optional out param */);
- DLOG_IF(ERROR, err) << "Call to set process name failed, err " << err;
+ OSSTATUS_DLOG_IF(ERROR, err != noErr, err)
+ << "Call to set process name failed";
}
// Converts a NSImage to a CGImageRef. Normally, the system frameworks can do