diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index c18854132a..115f31a042 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -174,6 +174,7 @@ static_library("rtc_base_approved") { sources += [ "logging.cc", "logging.h", + "logging_mac.mm", ] } } diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index 0fb79bedef..0e6198c1c4 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -160,8 +160,19 @@ 'sources': [ 'logging.cc', 'logging.h', + 'logging_mac.mm', ], }], + ['OS=="mac" and build_with_chromium==0', { + 'all_dependent_settings': { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + # needed for logging_mac.mm + '-framework Foundation', + ], + }, + }, + }], # OS=="mac" and build_with_chromium==0 ], }, { diff --git a/webrtc/base/logging.cc b/webrtc/base/logging.cc index 019a31623b..8f7d33cac7 100644 --- a/webrtc/base/logging.cc +++ b/webrtc/base/logging.cc @@ -171,10 +171,8 @@ LogMessage::LogMessage(const char* file, #endif // WEBRTC_WIN #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) case ERRCTX_OSSTATUS: { - tmp << " " << nonnull(GetMacOSStatusErrorString(err), "Unknown error"); - if (const char* desc = GetMacOSStatusCommentString(err)) { - tmp << ": " << desc; - } + std::string desc(DescriptionFromOSStatus(err)); + tmp << " " << (desc.empty() ? "Unknown error" : desc.c_str()); break; } #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) diff --git a/webrtc/base/logging.h b/webrtc/base/logging.h index 8c7b3f70e5..886b5d88f7 100644 --- a/webrtc/base/logging.h +++ b/webrtc/base/logging.h @@ -51,6 +51,10 @@ #include #include +#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) +#include +#endif + #include "webrtc/base/basictypes.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/thread_annotations.h" @@ -80,6 +84,11 @@ struct ConstantLabel { int value; const char * label; }; const char* FindLabel(int value, const ConstantLabel entries[]); std::string ErrorName(int err, const ConstantLabel* err_table); +#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) +// Returns a UTF8 description from an OS X Status error. +std::string DescriptionFromOSStatus(OSStatus err); +#endif + ////////////////////////////////////////////////////////////////////// // Note that the non-standard LoggingSeverity aliases exist because they are diff --git a/webrtc/base/logging_mac.mm b/webrtc/base/logging_mac.mm new file mode 100644 index 0000000000..ffee3541a4 --- /dev/null +++ b/webrtc/base/logging_mac.mm @@ -0,0 +1,22 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/base/logging.h" + +#import + + +namespace rtc { +std::string DescriptionFromOSStatus(OSStatus err) { + NSError* error = + [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; + return error.description.UTF8String; +} +} // namespace rtc