1// Copyright 2012 The Chromium Authors 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 "build/build_config.h" 12 13#if !BUILDFLAG(IS_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), 30 status_(status) { 31} 32 33OSStatusLogMessage::~OSStatusLogMessage() { 34#if BUILDFLAG(IS_IOS) 35 // TODO(crbug.com/546375): Consider using NSError with NSOSStatusErrorDomain 36 // to try to get a description of the failure. 37 stream() << ": " << status_; 38#else 39 stream() << ": " 40 << DescriptionFromOSStatus(status_) 41 << " (" 42 << status_ 43 << ")"; 44#endif 45} 46 47} // namespace logging 48