Commit d90951b3 authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

fuchsia: Add ZX_LOG and friends

Bug: 789213
Change-Id: I26ff91e89a49fdb63759fdcdbe5e46bdb413a425
Reviewed-on: https://chromium-review.googlesource.com/794347
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519909}
parent 609b671a
......@@ -1277,6 +1277,8 @@ jumbo_component("base") {
"files/file_path_watcher_fuchsia.cc",
"fuchsia/default_job.cc",
"fuchsia/default_job.h",
"fuchsia/fuchsia_logging.cc",
"fuchsia/fuchsia_logging.h",
"fuchsia/scoped_zx_handle.h",
"memory/shared_memory_fuchsia.cc",
"memory/shared_memory_handle_fuchsia.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/fuchsia/fuchsia_logging.h"
#include <zircon/status.h>
#include <iomanip>
namespace logging {
ZxLogMessage::ZxLogMessage(const char* file_path,
int line,
LogSeverity severity,
zx_status_t zx_err)
: LogMessage(file_path, line, severity), zx_err_(zx_err) {}
ZxLogMessage::~ZxLogMessage() {
// zx_status_t error values are negative, so log the numeric version as
// decimal rather than hex. This is also useful to match zircon/errors.h for
// grepping.
stream() << ": " << zx_status_get_string(zx_err_) << " (" << zx_err_ << ")";
}
} // namespace logging
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_FUCHSIA_FUCHSIA_LOGGING_H_
#define BASE_FUCHSIA_FUCHSIA_LOGGING_H_
#include <zircon/types.h>
#include "base/base_export.h"
#include "base/logging.h"
#include "base/macros.h"
#include "build/build_config.h"
// Use the ZX_LOG family of macros along with a zx_status_t containing a Zircon
// error. The error value will be decoded so that logged messages explain the
// error.
namespace logging {
class BASE_EXPORT ZxLogMessage : public logging::LogMessage {
public:
ZxLogMessage(const char* file_path,
int line,
LogSeverity severity,
zx_status_t zx_err);
~ZxLogMessage();
private:
zx_status_t zx_err_;
DISALLOW_COPY_AND_ASSIGN(ZxLogMessage);
};
} // namespace logging
#define ZX_LOG_STREAM(severity, zx_err) \
COMPACT_GOOGLE_LOG_EX_##severity(ZxLogMessage, zx_err).stream()
#define ZX_LOG(severity, zx_err) \
LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), LOG_IS_ON(severity))
#define ZX_LOG_IF(severity, condition, zx_err) \
LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \
LOG_IS_ON(severity) && (condition))
#define ZX_CHECK(condition, zx_err) \
LAZY_STREAM(ZX_LOG_STREAM(FATAL, zx_err), !(condition)) \
<< "Check failed: " #condition << ". "
#define ZX_DLOG(severity, zx_err) \
LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), DLOG_IS_ON(severity))
#define ZX_DLOG_IF(severity, condition, zx_err) \
LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \
DLOG_IS_ON(severity) && (condition))
#define ZX_DCHECK(condition, zx_err) \
LAZY_STREAM(ZX_LOG_STREAM(FATAL, zx_err), DCHECK_IS_ON() && !(condition)) \
<< "Check failed: " #condition << ". "
#endif // BASE_FUCHSIA_FUCHSIA_LOGGING_H_
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/strings/string_piece.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -28,6 +29,10 @@
#include <windows.h>
#endif // OS_WIN
#if defined(OS_FUCHSIA)
#include "base/fuchsia/fuchsia_logging.h"
#endif
namespace logging {
namespace {
......@@ -635,6 +640,26 @@ TEST_F(LoggingTest, AsanConditionalDCheckFeature) {
}
#endif // DCHECK_IS_ON() && defined(SYZYASAN)
#if defined(OS_FUCHSIA)
TEST_F(LoggingTest, FuchsiaLogging) {
MockLogSource mock_log_source;
EXPECT_CALL(mock_log_source, Log())
.Times(DCHECK_IS_ON() ? 2 : 1)
.WillRepeatedly(Return("log message"));
SetMinLogLevel(LOG_INFO);
EXPECT_TRUE(LOG_IS_ON(INFO));
EXPECT_TRUE((DCHECK_IS_ON() != 0) == DLOG_IS_ON(INFO));
ZX_LOG(INFO, ZX_ERR_INTERNAL) << mock_log_source.Log();
ZX_DLOG(INFO, ZX_ERR_INTERNAL) << mock_log_source.Log();
ZX_CHECK(true, ZX_ERR_INTERNAL);
ZX_DCHECK(true, ZX_ERR_INTERNAL);
}
#endif // defined(OS_FUCHSIA)
} // namespace
} // namespace logging
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment