Skip to content

Commit fd17433

Browse files
authored
Merge pull request #39 from qorix-group/arkjedrz_mw-log-subscriber
log: Rust-based backend implementation
2 parents 268b5c9 + 5c2b8b0 commit fd17433

File tree

14 files changed

+463
-13
lines changed

14 files changed

+463
-13
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/stdout_logger",
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/stdout_logger",
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+
stdout_logger = { path = "src/log/stdout_logger" }
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/stdout_logger",
22+
],
23+
)

examples/log_builtin/Cargo.toml

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

examples/log_builtin/src/main.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 stdout_logger::StdoutLoggerBuilder;
18+
19+
fn main() {
20+
// Initialize logger.
21+
StdoutLoggerBuilder::new()
22+
.context("EXAMPLE")
23+
.show_module(true)
24+
.show_file(true)
25+
.show_line(true)
26+
.log_level(LevelFilter::Info)
27+
.set_as_default_logger();
28+
29+
// Example logs.
30+
trace!("trace log - hidden!");
31+
debug!("debug log - hidden!");
32+
info!("info log");
33+
warn!("warn log");
34+
error!("error log");
35+
fatal!("fatal log");
36+
37+
// Logs with changed context.
38+
trace!(context: "CHANGED", "trace log - hidden!");
39+
debug!(context: "CHANGED", "debug log - hidden!");
40+
info!(context: "CHANGED", "info log");
41+
warn!(context: "CHANGED", "warn log");
42+
error!(context: "CHANGED", "error log");
43+
fatal!(context: "CHANGED", "fatal log");
44+
}
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
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use mw_log::{debug, error, fatal, info, trace, warn, LevelFilter};
2121
fn main() {
2222
// Initialize logger.
2323
mw_log::set_max_level(LevelFilter::Info);
24-
let result = mw_log::set_global_logger(Box::new(ExampleLogger));
25-
if result.is_err() {
26-
panic!("unable to set logger")
24+
if let Err(e) = mw_log::set_global_logger(Box::new(ExampleLogger)) {
25+
panic!("unable to set logger: {e}");
2726
}
2827

2928
// Example logs.

src/log/mw_log/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ pub trait Log: Sync + Send {
311311
fn context(&self) -> &str;
312312

313313
/// Logs the [`Record`].
314+
///
315+
/// # For implementors
316+
///
317+
/// Note that [`Log::enabled`] is *not* necessarily called before this method.
318+
/// Implementations should perform all necessary filtering internally.
314319
fn log(&self, record: &Record);
315320

316321
/// Flushes any buffered records.

0 commit comments

Comments
 (0)