Skip to content

Commit d31fb8e

Browse files
committed
log: Rust-based backend implementation
Basic implementation creating a string, printed to stderr.
1 parent a6cd4b0 commit d31fb8e

File tree

12 files changed

+442
-4
lines changed

12 files changed

+442
-4
lines changed

Cargo.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ default-members = [
2020
"src/log/mw_log",
2121
"src/log/mw_log_fmt",
2222
"src/log/mw_log_fmt_macro",
23+
"src/log/mw_log_subscriber",
2324
]
2425
# Include tests and examples as a member for IDE support and Bazel builds.
2526
members = [
2627
"src/containers",
2728
"src/log/mw_log",
2829
"src/log/mw_log_fmt",
2930
"src/log/mw_log_fmt_macro",
30-
"examples/log_example",
31+
"src/log/mw_log_subscriber",
32+
"examples/log_builtin",
33+
"examples/log_custom",
3134
]
3235

3336
[workspace.package]
@@ -40,6 +43,7 @@ authors = ["S-CORE Contributors"]
4043
mw_log = { path = "src/log/mw_log" }
4144
mw_log_fmt = { path = "src/log/mw_log_fmt" }
4245
mw_log_fmt_macro = { path = "src/log/mw_log_fmt_macro" }
46+
mw_log_subscriber = { path = "src/log/mw_log_subscriber" }
4347

4448
[workspace.lints.clippy]
4549
std_instead_of_core = "warn"

examples/log_builtin/BUILD

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
load("@rules_rust//rust:defs.bzl", "rust_binary")
15+
16+
rust_binary(
17+
name = "log_builtin",
18+
srcs = glob(["src/**/*.rs"]),
19+
deps = [
20+
"//src/log/mw_log",
21+
"//src/log/mw_log_subscriber",
22+
],
23+
)

examples/log_builtin/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "log_builtin"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
7+
8+
[dependencies]
9+
mw_log.workspace = true
10+
mw_log_subscriber.workspace = true
11+
12+
13+
[lints]
14+
workspace = true

examples/log_builtin/src/main.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
//! Example app utilizing built-in backend implementation.
15+
16+
use mw_log::{debug, error, fatal, info, trace, warn, LevelFilter};
17+
use mw_log_subscriber::MwLoggerBuilder;
18+
19+
fn main() {
20+
// Initialize logger.
21+
MwLoggerBuilder::new()
22+
.context("EXAMPLE")
23+
.log_level(LevelFilter::Info)
24+
.set_as_default_logger();
25+
26+
// Example logs.
27+
trace!("trace log - hidden!");
28+
debug!("debug log - hidden!");
29+
info!("info log");
30+
warn!("warn log");
31+
error!("error log");
32+
fatal!("fatal log");
33+
34+
// Logs with changed context.
35+
trace!(context: "CHANGED", "trace log - hidden!");
36+
debug!(context: "CHANGED", "debug log - hidden!");
37+
info!(context: "CHANGED", "info log");
38+
warn!(context: "CHANGED", "warn log");
39+
error!(context: "CHANGED", "error log");
40+
fatal!(context: "CHANGED", "fatal log");
41+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
load("@rules_rust//rust:defs.bzl", "rust_binary")
1515

1616
rust_binary(
17-
name = "log_example",
17+
name = "log_custom",
1818
srcs = glob(["src/**/*.rs"]),
1919
deps = [
2020
"//src/log/mw_log",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# *******************************************************************************
1313

1414
[package]
15-
name = "log_example"
15+
name = "log_custom"
1616
version.workspace = true
1717
authors.workspace = true
1818
edition.workspace = true

src/log/mw_log_subscriber/BUILD

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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_library", "rust_test")
14+
15+
rust_library(
16+
name = "mw_log_subscriber",
17+
srcs = glob(["**/*.rs"]),
18+
visibility = ["//visibility:public"],
19+
deps = [
20+
"//src/log/mw_log",
21+
],
22+
)
23+
24+
rust_test(
25+
name = "tests",
26+
crate = "mw_log_subscriber",
27+
tags = [
28+
"unit_tests",
29+
"ut",
30+
],
31+
)

0 commit comments

Comments
 (0)