Skip to content

Commit d9cb702

Browse files
authored
Merge pull request #12 from qorix-group/piotrkorkus_fix_logger
Refactor tracing subscriber initialization
2 parents a2f9cde + 2367017 commit d9cb702

File tree

6 files changed

+29
-38
lines changed

6 files changed

+29
-38
lines changed

MODULE.bazel

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717
module(
1818
name = "score_test_scenarios",
19-
version = "0.3.0",
19+
version = "0.3.1",
2020
compatibility_level = 0,
2121
)
2222

2323
# Starlark language server
24-
bazel_dep(name = "score_starpls_lsp", version = "0.1.0")
24+
bazel_dep(name = "score_starpls_lsp", version = "0.1.0", dev_dependency = True)
2525

2626
# Python rules.
27-
bazel_dep(name = "rules_python", version = "1.0.0")
27+
bazel_dep(name = "rules_python", version = "1.0.0", dev_dependency = True)
2828

2929
PYTHON_VERSION = "3.12"
3030

31-
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
31+
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
3232
python.toolchain(
3333
is_default = True,
3434
python_version = PYTHON_VERSION,
3535
)
3636
use_repo(python)
3737

3838
# C++ GoogleTest dependencies.
39-
bazel_dep(name = "googletest", version = "1.14.0")
39+
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)
4040

4141
# Rust rules.
4242
bazel_dep(name = "rules_rust", version = "0.56.0")
4343

4444
# C/C++ rules.
45-
bazel_dep(name = "rules_cc", version = "0.1.1")
45+
bazel_dep(name = "rules_cc", version = "0.1.1", dev_dependency = True)
4646

4747
# Rust module dependencies.
4848
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
@@ -51,15 +51,8 @@ rust.toolchain(
5151
versions = ["1.85.0"],
5252
)
5353

54-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
55-
crate.from_cargo(
56-
name = "test_scenarios_rust_crates",
57-
cargo_lockfile = "//test_scenarios_rust:Cargo.lock",
58-
manifests = [
59-
"//test_scenarios_rust:Cargo.toml",
60-
],
61-
)
62-
use_repo(crate, "test_scenarios_rust_crates")
63-
6454
# C++ base libs.
65-
bazel_dep(name = "score_baselibs", version = "0.1.2")
55+
bazel_dep(name = "score_baselibs", version = "0.1.2", dev_dependency = True)
56+
57+
# Score Rust crates.
58+
bazel_dep(name = "score_crates", version = "0.0.4")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "testing-utils"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
dependencies = ["pytest>=8.3.5", "pytest-html>=4.1.1", "pytest-repeat>=0.9.4"]
55
requires-python = ">=3.12"
66
authors = [

test_scenarios_rust/BUILD

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
load("@test_scenarios_rust_crates//:defs.bzl", "all_crate_deps")
1514

1615
rust_library(
1716
name = "test_scenarios_rust",
1817
srcs = glob(["src/**/*.rs"]),
1918
visibility = ["//visibility:public"],
20-
deps = all_crate_deps(normal = True),
19+
deps = [
20+
"@score_crates//:tracing",
21+
"@score_crates//:tracing_subscriber",
22+
],
2123
)
2224

2325
rust_test(
2426
name = "tests",
2527
crate = ":test_scenarios_rust",
2628
visibility = ["//visibility:private"],
27-
deps = all_crate_deps(normal = True),
29+
deps = [
30+
"@score_crates//:tracing",
31+
"@score_crates//:tracing_subscriber",
32+
],
2833
)

test_scenarios_rust/Cargo.lock

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

test_scenarios_rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "test_scenarios_rust"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2021"
55

66
[dependencies]

test_scenarios_rust/src/cli.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@
1212
// *******************************************************************************
1313
use crate::monotonic_clock::MonotonicClock;
1414
use crate::test_context::TestContext;
15-
use std::sync::Once;
1615
use tracing::Level;
16+
use tracing_subscriber::fmt::format::{Format, JsonFields};
1717
use tracing_subscriber::FmtSubscriber;
1818

19-
/// Tracing subscriber should be initialized only once.
20-
static TRACING_SUBSCRIBER_INIT: Once = Once::new();
21-
22-
fn init_tracing_subscriber() {
23-
let subscriber = FmtSubscriber::builder()
19+
/// Create a tracing subscriber that outputs logs in JSON format with monotonic timestamps.
20+
/// # Returns
21+
/// configured `FmtSubscriber`.
22+
pub fn create_tracing_subscriber(
23+
) -> FmtSubscriber<JsonFields, Format<tracing_subscriber::fmt::format::Json, MonotonicClock>> {
24+
FmtSubscriber::builder()
2425
.with_max_level(Level::TRACE)
2526
.with_thread_ids(true)
2627
.with_timer(MonotonicClock::new())
2728
.json()
28-
.finish();
29-
30-
tracing::subscriber::set_global_default(subscriber)
31-
.expect("Setting default subscriber failed!");
29+
.finish()
3230
}
3331

3432
/// Test scenario arguments.
@@ -154,11 +152,6 @@ pub fn run_cli_app(raw_arguments: &[String], test_context: &TestContext) -> Resu
154152
None => return Err("Test scenario input must be provided".to_string()),
155153
};
156154

157-
// Initialize tracing subscriber.
158-
TRACING_SUBSCRIBER_INIT.call_once(|| {
159-
init_tracing_subscriber();
160-
});
161-
162155
test_context.run(&scenario_name, &scenario_input)
163156
}
164157

0 commit comments

Comments
 (0)