Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
resolver = "2"
# Split to default members without tests and examples.
# Used when executing cargo from project root.
default-members = ["src/containers", "src/log/mw_log_fmt"]
default-members = [
"src/containers",
"src/log/mw_log_fmt",
"src/log/mw_log_fmt_macro",
]
# Include tests and examples as a member for IDE support and Bazel builds.
members = ["src/containers", "src/log/mw_log_fmt"]
members = ["src/containers", "src/log/mw_log_fmt", "src/log/mw_log_fmt_macro"]


[workspace.package]
Expand All @@ -16,6 +20,7 @@ authors = ["S-CORE Contributors"]

[workspace.dependencies]
mw_log_fmt = { path = "src/log/mw_log_fmt" }
mw_log_fmt_macro = { path = "src/log/mw_log_fmt_macro" }


[workspace.lints.clippy]
Expand Down
6 changes: 2 additions & 4 deletions docs/baselibs_rust/log/architecture/_assets/interface.puml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ package log <<component>> {
+trace!(...) : ()
}

class mw_log_macro <<module>> {
class mw_log_fmt_macro <<module>> {
+mw_log_format_args!(format_string: &str, args...) : Arguments<'_>
+mw_log_format_args_nl!(format_string: &str, args...) : Arguments<'_>
}

package mw_log_fmt {
Expand All @@ -51,13 +50,12 @@ package log <<component>> {
+write(output: &mut dyn ScoreWrite, args: Arguments<'_>) : Result

+score_write!(format_string: &str, args...) : Result
+score_writeln!(format_string: &str, args...) : Result
}
}

mw_log -- Level
mw_log -- LevelFilter
mw_log -- mw_log_macro
mw_log -- mw_log_fmt_macro
mw_log -right- mw_log_fmt
}

Expand Down
4 changes: 2 additions & 2 deletions docs/baselibs_rust/log/architecture/_assets/static_view.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package "log" <<component>> {

component "mw_log_fmt"

component "mw_log_macro"
component "mw_log_fmt_macro"

mw_log ..> mw_log_fmt : use
mw_log ..> mw_log_macro : use
mw_log ..> mw_log_fmt_macro : use
}

component "mw_log_subscriber" <<component>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ package "mw_log_fmt crate" {
+write(output: &mut dyn ScoreWrite, args: Arguments<'_>) : Result

+score_write!(format_string: &str, args...) : Result
+score_writeln!(format_string: &str, args...) : Result
}
note top
Provided macros can be used for implementing custom formatting traits.
Expand All @@ -217,10 +216,9 @@ package "mw_log_fmt crate" {
mw_log_fmt -- Arguments
}

package "mw_log_macro crate" {
+class mw_log_macro <<module>> {
package "mw_log_fmt_macro crate" {
+class mw_log_fmt_macro <<module>> {
+mw_log_format_args!(format_string: &str, args...) : Arguments<'_>
+mw_log_format_args_nl!(format_string: &str, args...) : Arguments<'_>
}

note top
Expand Down Expand Up @@ -262,7 +260,7 @@ package "mw_log_subscriber crate" {
}

"mw_log crate" -[hidden]down-> "mw_log_fmt crate"
"mw_log crate" -[hidden]up-> "mw_log_macro crate"
"mw_log crate" -[hidden]up-> "mw_log_fmt_macro crate"

"mw_log crate" -[hidden]down------> "mw_log_subscriber crate"
"mw_log_fmt crate" -[hidden]down------> "mw_log_subscriber crate"
Expand Down
6 changes: 3 additions & 3 deletions docs/baselibs_rust/log/detailed_design/_assets/log_op.puml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ participant "mw_log <<module>>" as mw_log
end box

box #LightGreen
participant "mw_log_macro <<module>>" as mw_log_macro
participant "mw_log_fmt_macro <<module>>" as mw_log_fmt_macro
end box

box #LightPink
Expand Down Expand Up @@ -36,8 +36,8 @@ alt log-level-check-failed
mw_log --> actor

else log-level-check-passed
mw_log -> mw_log_macro : mw_log_format_args!()
mw_log_macro --> mw_log
mw_log -> mw_log_fmt_macro : mw_log_format_args!()
mw_log_fmt_macro --> mw_log

mw_log -> logger : log()

Expand Down
4 changes: 3 additions & 1 deletion docs/baselibs_rust/log/detailed_design/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Log component consists of three units:

- `mw_log` - modelled after `log` Rust library.
- `mw_log_fmt` - replacement for `core::fmt` provided by Rust core library.
- `mw_log_macro` - replacement for `format_args` macro provided by Rust compiler.
- `mw_log_fmt_macro` - replacement for macros provided by Rust compiler:
- `mw_log_format_args!` - replacement for `format_args!`
- `ScoreDebug` - replacement for `Debug`

Most common approach in Rust is that formatting always results in a string.
This means that the `log` library always receives a pre-formatted string.
Expand Down
14 changes: 0 additions & 14 deletions src/log/mw_log_fmt/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,3 @@ macro_rules! score_write {
$crate::write($dst, mw_log::__private_api::format_args!($($arg)*))
};
}

/// Writes data using provided writer, with a newline appended.
///
/// For more information, see [`score_write!`].
#[macro_export]
macro_rules! score_writeln {
($dst:expr $(,)?) => {
$crate::score_write!($dst, "\n")
};
($dst:expr, $($arg:tt)*) => {
// TODO: `mw_log::__private_api` will become available in future PRs.
$crate::write($dst, mw_log::__private_api::format_args_nl!($($arg)*))
};
}
42 changes: 42 additions & 0 deletions src/log/mw_log_fmt_macro/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@rules_rust//rust:defs.bzl", "rust_proc_macro", "rust_test")

rust_proc_macro(
name = "mw_log_fmt_macro",
srcs = glob(["*.rs"]),
# TODO: expose required interface through `mw_log` and make it private again.
# visibility = ["//visibility:private"],
visibility = ["//visibility:public"],
deps = [
"//src/log/mw_log_fmt",
"@score_crates//:proc_macro2",
"@score_crates//:quote",
"@score_crates//:syn",
],
)

rust_test(
name = "tests",
srcs = glob(["tests/**/*.rs"]),
proc_macro_deps = [
"//src/log/mw_log_fmt_macro",
],
tags = [
"unit_tests",
"ut",
],
deps = [
"//src/log/mw_log_fmt",
],
)
32 changes: 32 additions & 0 deletions src/log/mw_log_fmt_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

[package]
name = "mw_log_fmt_macro"
version.workspace = true
authors.workspace = true
readme.workspace = true
edition.workspace = true

[lib]
proc-macro = true
path = "lib.rs"

[dependencies]
syn = { version = "2", features = ["full"] }
quote = "1"
proc-macro2 = "1"
mw_log_fmt.workspace = true

[lints]
workspace = true
Loading
Loading