mac_logging.mm 1.2 KB

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