Skip to content

Commit 8992014

Browse files
committed
log: mw_log_fmt_macro implementation
- Replacement for `format_args!` macros. - Unit tests.
1 parent 4e00a73 commit 8992014

File tree

12 files changed

+1227
-13
lines changed

12 files changed

+1227
-13
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/module/log/architecture/_assets/interface.puml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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<'_>
4242
+mw_log_format_args_nl!(format_string: &str, args...) : Arguments<'_>
4343
}
@@ -57,7 +57,7 @@ package log <<component>> {
5757

5858
mw_log -- Level
5959
mw_log -- LevelFilter
60-
mw_log -- mw_log_macro
60+
mw_log -- mw_log_fmt_macro
6161
mw_log -right- mw_log_fmt
6262
}
6363

docs/module/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/module/log/detailed_design/_assets/class_diagram.puml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ package "mw_log_fmt crate" {
217217
mw_log_fmt -- Arguments
218218
}
219219

220-
package "mw_log_macro crate" {
221-
+class mw_log_macro <<module>> {
220+
package "mw_log_fmt_macro crate" {
221+
+class mw_log_fmt_macro <<module>> {
222222
+mw_log_format_args!(format_string: &str, args...) : Arguments<'_>
223223
+mw_log_format_args_nl!(format_string: &str, args...) : Arguments<'_>
224224
}
@@ -262,7 +262,7 @@ package "mw_log_subscriber crate" {
262262
}
263263

264264
"mw_log crate" -[hidden]down-> "mw_log_fmt crate"
265-
"mw_log crate" -[hidden]up-> "mw_log_macro crate"
265+
"mw_log crate" -[hidden]up-> "mw_log_fmt_macro crate"
266266

267267
"mw_log crate" -[hidden]down------> "mw_log_subscriber crate"
268268
"mw_log_fmt crate" -[hidden]down------> "mw_log_subscriber crate"

docs/module/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/module/log/detailed_design/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ 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 `format_args` macro provided by Rust compiler.
4040

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

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)