Commit 212909ff authored by David Dorwin's avatar David Dorwin Committed by Commit Bot

[fuchsia] Add ScopedFxLogger

Also add a function for creating an fx_logger from a LogSink.
These will be used in subsequent CLs.

Bug: 1136681,1088094
Change-Id: I9e4fe1b2b0640fa3f7eb9e0891ae9ef1a80b8bcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530259
Auto-Submit: David Dorwin <ddorwin@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826204}
parent 2fdf1731
...@@ -1564,6 +1564,8 @@ component("base") { ...@@ -1564,6 +1564,8 @@ component("base") {
"fuchsia/intl_profile_watcher.h", "fuchsia/intl_profile_watcher.h",
"fuchsia/process_context.cc", "fuchsia/process_context.cc",
"fuchsia/process_context.h", "fuchsia/process_context.h",
"fuchsia/scoped_fx_logger.cc",
"fuchsia/scoped_fx_logger.h",
"fuchsia/scoped_service_binding.h", "fuchsia/scoped_service_binding.h",
"fuchsia/scoped_service_publisher.h", "fuchsia/scoped_service_publisher.h",
"fuchsia/service_provider_impl.cc", "fuchsia/service_provider_impl.cc",
...@@ -1619,10 +1621,12 @@ component("base") { ...@@ -1619,10 +1621,12 @@ component("base") {
public_deps += [ public_deps += [
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.intl", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.intl",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.logger",
"//third_party/fuchsia-sdk/sdk/pkg/async", "//third_party/fuchsia-sdk/sdk/pkg/async",
"//third_party/fuchsia-sdk/sdk/pkg/fdio", "//third_party/fuchsia-sdk/sdk/pkg/fdio",
"//third_party/fuchsia-sdk/sdk/pkg/fidl_cpp", "//third_party/fuchsia-sdk/sdk/pkg/fidl_cpp",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp", "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
"//third_party/fuchsia-sdk/sdk/pkg/syslog",
"//third_party/fuchsia-sdk/sdk/pkg/vfs_cpp", "//third_party/fuchsia-sdk/sdk/pkg/vfs_cpp",
"//third_party/fuchsia-sdk/sdk/pkg/zx", "//third_party/fuchsia-sdk/sdk/pkg/zx",
] ]
......
// Copyright 2020 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/scoped_fx_logger.h"
#include "base/fuchsia/fuchsia_logging.h"
namespace base {
ScopedFxLogger CreateFxLoggerFromLogSink(
fuchsia::logger::LogSinkHandle log_sink) {
// TODO(bugs.fuchsia.dev/63529): Use |log_sink_socket| when available.
zx::socket client_end, request_end;
zx_status_t status =
zx::socket::create(ZX_SOCKET_DATAGRAM, &client_end, &request_end);
if (status != ZX_OK) {
return nullptr;
}
fuchsia::logger::LogSinkSyncPtr log_sink_ptr;
log_sink_ptr.Bind(std::move(log_sink));
log_sink_ptr->Connect(std::move(request_end));
fx_logger_config_t config = {
// Selecting based on log level is handled outside the fx_logger.
.min_severity = FX_LOG_ALL,
.console_fd = -1,
.log_service_channel = client_end.release(),
// Do not set any custom tags.
.tags = nullptr,
.num_tags = 0,
};
fx_logger_t* fx_logger = nullptr;
status = fx_logger_create(&config, &fx_logger);
if (status != ZX_OK) {
ZX_LOG(ERROR, status) << "fx_logger_create";
return nullptr;
}
return ScopedFxLogger(fx_logger);
}
} // namespace base
// Copyright 2020 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_SCOPED_FX_LOGGER_H_
#define BASE_FUCHSIA_SCOPED_FX_LOGGER_H_
#include <fuchsia/logger/cpp/fidl.h>
#include <lib/syslog/logger.h>
#include <memory>
#include "base/base_export.h"
namespace base {
namespace internal {
struct FxLoggerDeleter {
inline void operator()(fx_logger_t* ptr) const { fx_logger_destroy(ptr); }
};
} // namespace internal
using ScopedFxLogger = std::unique_ptr<fx_logger_t, internal::FxLoggerDeleter>;
// Creates a new logger connected to the specified |log_sink| service.
// The logger is configured to log all severities of message, and has no
// custom tags set.
// Returns null if creation of the new logger fails.
BASE_EXPORT ScopedFxLogger
CreateFxLoggerFromLogSink(fuchsia::logger::LogSinkHandle log_sink);
} // namespace base
#endif // BASE_FUCHSIA_SCOPED_FX_LOGGER_H_
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