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#include "base/mac/mac_logging.h" 6 7#import <Foundation/Foundation.h> 8 9#include <iomanip> 10 11#include "util/build_config.h" 12 13#if !defined(OS_IOS) 14#include <CoreServices/CoreServices.h> 15#endif 16 17namespace logging { 18 19std::string DescriptionFromOSStatus(OSStatus err) { 20 NSError* error = 21 [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; 22 return error.description.UTF8String; 23} 24 25OSStatusLogMessage::OSStatusLogMessage(const char* file_path, 26 int line, 27 LogSeverity severity, 28 OSStatus status) 29 : LogMessage(file_path, line, severity), status_(status) {} 30 31OSStatusLogMessage::~OSStatusLogMessage() { 32#if defined(OS_IOS) 33 // TODO(crbug.com/546375): Consider using NSError with NSOSStatusErrorDomain 34 // to try to get a description of the failure. 35 stream() << ": " << status_; 36#else 37 stream() << ": " << DescriptionFromOSStatus(status_) << " (" << status_ 38 << ")"; 39#endif 40} 41 42} // namespace logging 43