Skip to content

Commit b283d54

Browse files
authored
Merge pull request #14 from qorix-group/arkjedrz_mw-log-macro
log: `mw_log_fmt_macro` implementation
2 parents 9ee64ac + a9b44fa commit b283d54

File tree

17 files changed

+1561
-31
lines changed

17 files changed

+1561
-31
lines changed

Cargo.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
resolver = "2"
33
# Split to default members without tests and examples.
44
# Used when executing cargo from project root.
5-
default-members = ["src/containers", "src/log/mw_log_fmt"]
5+
default-members = [
6+
"src/containers",
7+
"src/log/mw_log_fmt",
8+
"src/log/mw_log_fmt_macro",
9+
]
610
# Include tests and examples as a member for IDE support and Bazel builds.
7-
members = ["src/containers", "src/log/mw_log_fmt"]
11+
members = ["src/containers", "src/log/mw_log_fmt", "src/log/mw_log_fmt_macro"]
812

913

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

1721
[workspace.dependencies]
1822
mw_log_fmt = { path = "src/log/mw_log_fmt" }
23+
mw_log_fmt_macro = { path = "src/log/mw_log_fmt_macro" }
1924

2025

2126
[workspace.lints.clippy]

docs/baselibs_rust/log/architecture/_assets/interface.puml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ package log <<component>> {
3737
+trace!(...) : ()
3838
}
3939

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

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

5352
+score_write!(format_string: &str, args...) : Result
54-
+score_writeln!(format_string: &str, args...) : Result
5553
}
5654
}
5755

5856
mw_log -- Level
5957
mw_log -- LevelFilter
60-
mw_log -- mw_log_macro
58+
mw_log -- mw_log_fmt_macro
6159
mw_log -right- mw_log_fmt
6260
}
6361

docs/baselibs_rust/log/architecture/_assets/static_view.puml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ package "log" <<component>> {
55

66
component "mw_log_fmt"
77

8-
component "mw_log_macro"
8+
component "mw_log_fmt_macro"
99

1010
mw_log ..> mw_log_fmt : use
11-
mw_log ..> mw_log_macro : use
11+
mw_log ..> mw_log_fmt_macro : use
1212
}
1313

1414
component "mw_log_subscriber" <<component>>

docs/baselibs_rust/log/detailed_design/_assets/class_diagram.puml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ package "mw_log_fmt crate" {
195195
+write(output: &mut dyn ScoreWrite, args: Arguments<'_>) : Result
196196

197197
+score_write!(format_string: &str, args...) : Result
198-
+score_writeln!(format_string: &str, args...) : Result
199198
}
200199
note top
201200
Provided macros can be used for implementing custom formatting traits.
@@ -217,10 +216,9 @@ package "mw_log_fmt crate" {
217216
mw_log_fmt -- Arguments
218217
}
219218

220-
package "mw_log_macro crate" {
221-
+class mw_log_macro <<module>> {
219+
package "mw_log_fmt_macro crate" {
220+
+class mw_log_fmt_macro <<module>> {
222221
+mw_log_format_args!(format_string: &str, args...) : Arguments<'_>
223-
+mw_log_format_args_nl!(format_string: &str, args...) : Arguments<'_>
224222
}
225223

226224
note top
@@ -262,7 +260,7 @@ package "mw_log_subscriber crate" {
262260
}
263261

264262
"mw_log crate" -[hidden]down-> "mw_log_fmt crate"
265-
"mw_log crate" -[hidden]up-> "mw_log_macro crate"
263+
"mw_log crate" -[hidden]up-> "mw_log_fmt_macro crate"
266264

267265
"mw_log crate" -[hidden]down------> "mw_log_subscriber crate"
268266
"mw_log_fmt crate" -[hidden]down------> "mw_log_subscriber crate"

docs/baselibs_rust/log/detailed_design/_assets/log_op.puml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ participant "mw_log <<module>>" as mw_log
77
end box
88

99
box #LightGreen
10-
participant "mw_log_macro <<module>>" as mw_log_macro
10+
participant "mw_log_fmt_macro <<module>>" as mw_log_fmt_macro
1111
end box
1212

1313
box #LightPink
@@ -36,8 +36,8 @@ alt log-level-check-failed
3636
mw_log --> actor
3737

3838
else log-level-check-passed
39-
mw_log -> mw_log_macro : mw_log_format_args!()
40-
mw_log_macro --> mw_log
39+
mw_log -> mw_log_fmt_macro : mw_log_format_args!()
40+
mw_log_fmt_macro --> mw_log
4141

4242
mw_log -> logger : log()
4343

docs/baselibs_rust/log/detailed_design/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Log component consists of three units:
3636

3737
- `mw_log` - modelled after `log` Rust library.
3838
- `mw_log_fmt` - replacement for `core::fmt` provided by Rust core library.
39-
- `mw_log_macro` - replacement for `format_args` macro provided by Rust compiler.
39+
- `mw_log_fmt_macro` - replacement for macros provided by Rust compiler:
40+
- `mw_log_format_args!` - replacement for `format_args!`
41+
- `ScoreDebug` - replacement for `Debug`
4042

4143
Most common approach in Rust is that formatting always results in a string.
4244
This means that the `log` library always receives a pre-formatted string.

src/log/mw_log_fmt/macros.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,3 @@ macro_rules! score_write {
2222
$crate::write($dst, mw_log::__private_api::format_args!($($arg)*))
2323
};
2424
}
25-
26-
/// Writes data using provided writer, with a newline appended.
27-
///
28-
/// For more information, see [`score_write!`].
29-
#[macro_export]
30-
macro_rules! score_writeln {
31-
($dst:expr $(,)?) => {
32-
$crate::score_write!($dst, "\n")
33-
};
34-
($dst:expr, $($arg:tt)*) => {
35-
// TODO: `mw_log::__private_api` will become available in future PRs.
36-
$crate::write($dst, mw_log::__private_api::format_args_nl!($($arg)*))
37-
};
38-
}

src/log/mw_log_fmt_macro/BUILD

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
load("@rules_rust//rust:defs.bzl", "rust_proc_macro", "rust_test")
14+
15+
rust_proc_macro(
16+
name = "mw_log_fmt_macro",
17+
srcs = glob(["*.rs"]),
18+
# TODO: expose required interface through `mw_log` and make it private again.
19+
# visibility = ["//visibility:private"],
20+
visibility = ["//visibility:public"],
21+
deps = [
22+
"//src/log/mw_log_fmt",
23+
"@score_crates//:proc_macro2",
24+
"@score_crates//:quote",
25+
"@score_crates//:syn",
26+
],
27+
)
28+
29+
rust_test(
30+
name = "tests",
31+
srcs = glob(["tests/**/*.rs"]),
32+
proc_macro_deps = [
33+
"//src/log/mw_log_fmt_macro",
34+
],
35+
tags = [
36+
"unit_tests",
37+
"ut",
38+
],
39+
deps = [
40+
"//src/log/mw_log_fmt",
41+
],
42+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
[package]
15+
name = "mw_log_fmt_macro"
16+
version.workspace = true
17+
authors.workspace = true
18+
readme.workspace = true
19+
edition.workspace = true
20+
21+
[lib]
22+
proc-macro = true
23+
path = "lib.rs"
24+
25+
[dependencies]
26+
syn = { version = "2", features = ["full"] }
27+
quote = "1"
28+
proc-macro2 = "1"
29+
mw_log_fmt.workspace = true
30+
31+
[lints]
32+
workspace = true

0 commit comments

Comments
 (0)