blob: ba3b50bc6a86e3fb4a6fbcb116ddda8572d60ba7 [file] [log] [blame]
Thirumurugan7ea0a5e2024-10-16 15:44:031// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/logging/rust_log_integration.h"
6
Collin Baker7cbc0d172025-03-19 21:02:017#include <stdint.h>
8
Thirumurugan7ea0a5e2024-10-16 15:44:039#include "base/logging.h"
Lukasz Anforowicz191a4d32024-11-12 01:48:0810#include "base/logging/log_severity.h"
Collin Bakerf0fd42e2025-03-21 16:47:3911#include "base/logging/rust_logger.rs.h"
12#include "third_party/rust/cxx/v1/cxx.h"
Thirumurugan7ea0a5e2024-10-16 15:44:0313
Peter Kasting811504a72025-01-09 03:18:5014namespace logging::internal {
Thirumurugan7ea0a5e2024-10-16 15:44:0315
Collin Bakere1e02fde2025-03-26 16:40:1616LogMessageRustWrapper::LogMessageRustWrapper(const char* file,
Collin Bakerf0fd42e2025-03-21 16:47:3917 int line,
18 ::logging::LogSeverity severity)
19 : log_message(file, line, severity) {}
20
21void LogMessageRustWrapper::write_to_stream(rust::Str str) {
22 log_message.stream().write(str.data(),
23 static_cast<std::streamsize>(str.size()));
24}
25
26void print_rust_log(const RustFmtArguments& msg,
Collin Bakere1e02fde2025-03-26 16:40:1627 const char* file,
Collin Baker7cbc0d172025-03-19 21:02:0128 int32_t line,
29 int32_t severity,
30 bool verbose) {
Lukasz Anforowicz191a4d32024-11-12 01:48:0831 // TODO(danakj): If `verbose` make the log equivalent to VLOG instead of LOG.
Collin Bakere1e02fde2025-03-26 16:40:1632 LogMessageRustWrapper wrapper(file, line, severity);
Collin Bakerf0fd42e2025-03-21 16:47:3933 msg.format(wrapper);
Thirumurugan7ea0a5e2024-10-16 15:44:0334}
35
Peter Kasting811504a72025-01-09 03:18:5036} // namespace logging::internal