Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fixes logging of target names with dashes (#7281)
Browse files Browse the repository at this point in the history
* Fixes logging of target names with dashes

There was a bug in tracing-core which resulted in not supporting dashes
in target names. This was fixed upstream. Besides that a test was added
to ensure that we don't break this again.

* Extend test
  • Loading branch information
bkchr authored Oct 8, 2020
1 parent 0aa4ab4 commit ffe1540
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 25 deletions.
19 changes: 11 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ pub fn init_logger(
mod tests {
use super::*;
use tracing::{metadata::Kind, subscriber::Interest, Callsite, Level, Metadata};
use std::{process::Command, env};

#[test]
fn test_logger_filters() {
let test_pattern = "afg=debug,sync=trace,client=warn,telemetry";
let test_pattern = "afg=debug,sync=trace,client=warn,telemetry,something-with-dash=error";
init_logger(&test_pattern, Default::default(), Default::default()).unwrap();

tracing::dispatcher::get_default(|dispatcher| {
Expand Down Expand Up @@ -369,6 +370,36 @@ mod tests {
assert!(test_filter("client", Level::WARN));

assert!(test_filter("telemetry", Level::TRACE));
assert!(test_filter("something-with-dash", Level::ERROR));
});
}

const EXPECTED_LOG_MESSAGE: &'static str = "yeah logging works as expected";

#[test]
fn dash_in_target_name_works() {
let executable = env::current_exe().unwrap();
let output = Command::new(executable)
.env("ENABLE_LOGGING", "1")
.args(&["--nocapture", "log_something_with_dash_target_name"])
.output()
.unwrap();

let output = String::from_utf8(output.stderr).unwrap();
assert!(output.contains(EXPECTED_LOG_MESSAGE));
}

/// This is no actual test, it will be used by the `dash_in_target_name_works` test.
/// The given test will call the test executable to only execute this test that
/// will only print `EXPECTED_LOG_MESSAGE` through logging while using a target
/// name that contains a dash. This ensures that targets names with dashes work.
#[test]
fn log_something_with_dash_target_name() {
if env::var("ENABLE_LOGGING").is_ok() {
let test_pattern = "test-target=info";
init_logger(&test_pattern, Default::default(), Default::default()).unwrap();

log::info!(target: "test-target", "{}", EXPECTED_LOG_MESSAGE);
}
}
}
6 changes: 3 additions & 3 deletions client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ rustc-hash = "1.1.0"
serde = "1.0.101"
serde_json = "1.0.41"
slog = { version = "2.5.2", features = ["nested-values"] }
tracing = "0.1.19"
tracing-core = "0.1.13"
tracing-subscriber = "0.2.10"
tracing = "0.1.21"
tracing-core = "0.1.17"
tracing-subscriber = "0.2.13"
sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" }
sc-telemetry = { version = "2.0.0", path = "../telemetry" }
2 changes: 1 addition & 1 deletion primitives/io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ log = { version = "0.4.8", optional = true }
futures = { version = "0.3.1", features = ["thread-pool"], optional = true }
parking_lot = { version = "0.10.0", optional = true }
tracing = { version = "0.1.19", default-features = false }
tracing-core = { version = "0.1.15", default-features = false}
tracing-core = { version = "0.1.17", default-features = false}

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion primitives/runtime-interface/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ sp-runtime = { version = "2.0.0", path = "../../runtime" }
sp-core = { version = "2.0.0", path = "../../core" }
sp-io = { version = "2.0.0", path = "../../io" }
tracing = "0.1.19"
tracing-core = "0.1.15"
tracing-core = "0.1.17"
22 changes: 11 additions & 11 deletions primitives/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
[dependencies]
sp-std = { version = "2.0.0", path = "../std", default-features = false}
codec = { version = "1.3.1", package = "parity-scale-codec", default-features = false, features = ["derive"]}
tracing = { version = "0.1.19", default-features = false }
tracing-core = { version = "0.1.16", default-features = false }
tracing = { version = "0.1.21", default-features = false }
tracing-core = { version = "0.1.17", default-features = false }
log = { version = "0.4.8", optional = true }
tracing-subscriber = { version = "0.2.10", optional = true, features = ["tracing-log"] }

[features]
default = [ "std" ]
with-tracing = [
"codec/derive",
"codec/full",
"codec/derive",
"codec/full",
]
std = [
"with-tracing",
"tracing/std",
"tracing-core/std",
"codec/std",
"sp-std/std",
"log",
"tracing-subscriber",
"with-tracing",
"tracing/std",
"tracing-core/std",
"codec/std",
"sp-std/std",
"log",
"tracing-subscriber",
]

0 comments on commit ffe1540

Please sign in to comment.