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/apple/osstatus_logging.h" 6 7#import <Foundation/Foundation.h> 8 9#include <iomanip> 10 11#include "base/immediate_crash.h" 12#include "base/scoped_clear_last_error.h" 13 14namespace logging { 15 16std::string DescriptionFromOSStatus(OSStatus err) { 17 NSError* error = [NSError errorWithDomain:NSOSStatusErrorDomain 18 code:err 19 userInfo:nil]; 20 return error.description.UTF8String; 21} 22 23OSStatusLogMessage::OSStatusLogMessage(const char* file_path, 24 int line, 25 LogSeverity severity, 26 OSStatus status) 27 : LogMessage(file_path, line, severity), status_(status) {} 28 29OSStatusLogMessage::~OSStatusLogMessage() { 30 AppendError(); 31} 32 33void OSStatusLogMessage::AppendError() { 34 // Don't let actions from this method affect the system error after returning. 35 base::ScopedClearLastError scoped_clear_last_error; 36 37 stream() << ": " << DescriptionFromOSStatus(status_) << " (" << status_ 38 << ")"; 39} 40 41OSStatusLogMessageFatal::~OSStatusLogMessageFatal() { 42 AppendError(); 43 Flush(); 44 base::ImmediateCrash(); 45} 46 47} // namespace logging 48