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

Fixes logging of target names with dashes #7281

Merged
3 commits merged into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

30 changes: 30 additions & 0 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ 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() {
Expand Down Expand Up @@ -371,4 +372,33 @@ mod tests {
assert!(test_filter("telemetry", Level::TRACE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can also add an example with dashes to this test 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

});
}

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

#[test]
fn dash_in_target_name_works() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test :)

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",
]