fuchsia_logging.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #ifndef BASE_FUCHSIA_FUCHSIA_LOGGING_H_
  5. #define BASE_FUCHSIA_FUCHSIA_LOGGING_H_
  6. #include <zircon/types.h>
  7. #include "base/base_export.h"
  8. #include "base/logging.h"
  9. #include "base/macros.h"
  10. #include "build/build_config.h"
  11. // Use the ZX_LOG family of macros along with a zx_status_t containing a Zircon
  12. // error. The error value will be decoded so that logged messages explain the
  13. // error.
  14. namespace logging {
  15. class BASE_EXPORT ZxLogMessage : public logging::LogMessage {
  16. public:
  17. ZxLogMessage(const char* file_path,
  18. int line,
  19. LogSeverity severity,
  20. zx_status_t zx_err);
  21. ~ZxLogMessage() override;
  22. private:
  23. zx_status_t zx_err_;
  24. DISALLOW_COPY_AND_ASSIGN(ZxLogMessage);
  25. };
  26. } // namespace logging
  27. #define ZX_LOG_STREAM(severity, zx_err) \
  28. COMPACT_GOOGLE_LOG_EX_##severity(ZxLogMessage, zx_err).stream()
  29. #define ZX_LOG(severity, zx_err) \
  30. LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), LOG_IS_ON(severity))
  31. #define ZX_LOG_IF(severity, condition, zx_err) \
  32. LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \
  33. LOG_IS_ON(severity) && (condition))
  34. #define ZX_CHECK(condition, zx_err) \
  35. LAZY_STREAM(ZX_LOG_STREAM(FATAL, zx_err), !(condition)) \
  36. << "Check failed: " #condition << ". "
  37. #define ZX_DLOG(severity, zx_err) \
  38. LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), DLOG_IS_ON(severity))
  39. #if DCHECK_IS_ON()
  40. #define ZX_DLOG_IF(severity, condition, zx_err) \
  41. LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \
  42. DLOG_IS_ON(severity) && (condition))
  43. #else // DCHECK_IS_ON()
  44. #define ZX_DLOG_IF(severity, condition, zx_err) EAT_STREAM_PARAMETERS
  45. #endif // DCHECK_IS_ON()
  46. #define ZX_DCHECK(condition, zx_err) \
  47. LAZY_STREAM(ZX_LOG_STREAM(DCHECK, zx_err), DCHECK_IS_ON() && !(condition)) \
  48. << "Check failed: " #condition << ". "
  49. #endif // BASE_FUCHSIA_FUCHSIA_LOGGING_H_