blob: 599f329b8aad265edeb20c30e369257d834229ee [file] [log] [blame]
// Copyright 2020 The Fuchsia 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 "log.h"
#include <fuchsia/boot/llcpp/fidl.h>
#include <lib/fdio/directory.h>
#include <lib/fdio/fd.h>
#include <lib/service/llcpp/service.h>
#include <lib/zx/debuglog.h>
#include <lib/zx/process.h>
zx_status_t log_to_debuglog() {
auto local = service::Connect<llcpp::fuchsia::boot::WriteOnlyLog>();
if (local.is_error()) {
return local.error_value();
}
auto write_only_log = fidl::BindSyncClient(std::move(*local));
auto result = write_only_log.Get();
if (result.status() != ZX_OK) {
return result.status();
}
char process_name[ZX_MAX_NAME_LEN] = {};
zx::process::self()->get_property(ZX_PROP_NAME, process_name, sizeof(process_name));
const char* tag = process_name;
fx_logger_config_t logger_config{
.min_severity = fx_logger_get_min_severity(fx_log_get_logger()),
.console_fd = -1,
.log_service_channel = ZX_HANDLE_INVALID,
.tags = &tag,
.num_tags = 1,
};
zx_status_t status = fdio_fd_create(result->log.release(), &logger_config.console_fd);
if (status != ZX_OK) {
return status;
}
return fx_log_reconfigure(&logger_config);
}