fuchsia_logging.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2017 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/fuchsia/fuchsia_logging.h"
  5. #include <zircon/status.h>
  6. #include <iomanip>
  7. #include "base/location.h"
  8. #include "base/process/process.h"
  9. #include "base/strings/string_piece.h"
  10. namespace logging {
  11. ZxLogMessage::ZxLogMessage(const char* file_path,
  12. int line,
  13. LogSeverity severity,
  14. zx_status_t zx_status)
  15. : LogMessage(file_path, line, severity), zx_status_(zx_status) {}
  16. ZxLogMessage::~ZxLogMessage() {
  17. // zx_status_t error values are negative, so log the numeric version as
  18. // decimal rather than hex. This is also useful to match zircon/errors.h for
  19. // grepping.
  20. stream() << ": " << zx_status_get_string(zx_status_) << " (" << zx_status_
  21. << ")";
  22. }
  23. } // namespace logging
  24. namespace base {
  25. fit::function<void(zx_status_t)> LogFidlErrorAndExitProcess(
  26. const Location& from_here,
  27. StringPiece protocol_name) {
  28. return [from_here, protocol_name](zx_status_t status) {
  29. {
  30. logging::ZxLogMessage(from_here.file_name(), from_here.line_number(),
  31. logging::LOGGING_ERROR, status)
  32. .stream()
  33. << protocol_name << " disconnected unexpectedly, exiting";
  34. }
  35. base::Process::TerminateCurrentProcessImmediately(1);
  36. };
  37. }
  38. } // namespace base