diff --git a/Cargo.lock b/Cargo.lock index 975363f84..ca3bf04bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,13 +476,11 @@ dependencies = [ "contract-metadata", "contract-transcode", "current_platform", - "env_logger", "heck", "hex", "impl-serde", "ink_metadata", "jsonrpsee", - "log", "pallet-contracts-primitives", "parity-scale-codec", "parity-wasm 0.45.0", @@ -498,6 +496,8 @@ dependencies = [ "subxt", "tempfile", "toml", + "tracing", + "tracing-subscriber 0.3.15", "url", "wabt", "walkdir", @@ -654,7 +654,6 @@ dependencies = [ "ink_primitives", "ink_storage", "itertools", - "log", "nom", "nom-supreme", "parity-scale-codec", @@ -663,6 +662,7 @@ dependencies = [ "serde_json", "sp-core", "sp-runtime", + "tracing", ] [[package]] @@ -1991,9 +1991,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "opaque-debug" @@ -3189,7 +3189,7 @@ dependencies = [ "sp-std", "tracing", "tracing-core", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -3550,9 +3550,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.34" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -3562,9 +3562,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" dependencies = [ "proc-macro2", "quote", @@ -3573,11 +3573,11 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.26" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ - "lazy_static", + "once_cell", "valuable", ] @@ -3634,6 +3634,20 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "tracing-subscriber" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b" +dependencies = [ + "ansi_term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + [[package]] name = "trie-db" version = "0.23.1" @@ -3663,7 +3677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] diff --git a/Cargo.toml b/Cargo.toml index 07a477914..173cabc15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,10 @@ include = [ ] [dependencies] -env_logger = "0.9.0" anyhow = "1.0.61" clap = { version = "3.2.16", features = ["derive", "env"] } -log = "0.4.17" +tracing = "0.1.36" +tracing-subscriber = "0.3.15" heck = "0.4.0" zip = { version = "0.6.2", default-features = false } parity-wasm = "0.45.0" diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 72cf7dc89..4f4792e8e 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -340,7 +340,7 @@ fn exec_cargo_dylint(crate_metadata: &CrateMetadata, verbosity: Verbosity) -> Re let tmp_dir = tempfile::Builder::new() .prefix("cargo-contract-dylint_") .tempdir()?; - log::debug!("Using temp workspace at '{}'", tmp_dir.path().display()); + tracing::debug!("Using temp workspace at '{}'", tmp_dir.path().display()); let driver = include_bytes!(concat!(env!("OUT_DIR"), "/ink-dylint-driver.zip")); crate::util::unzip(driver, tmp_dir.path().to_path_buf(), None)?; @@ -412,13 +412,13 @@ fn check_dylint_requirements(_working_dir: Option<&Path>) -> Result<()> { .stderr(std::process::Stdio::null()) .spawn() .map_err(|err| { - log::debug!("Error spawning `{:?}`", cmd); + tracing::debug!("Error spawning `{:?}`", cmd); err })? .wait() .map(|res| res.success()) .map_err(|err| { - log::debug!("Error waiting for `{:?}`: {:?}", cmd, err); + tracing::debug!("Error waiting for `{:?}`: {:?}", cmd, err); err }) }; @@ -610,11 +610,11 @@ fn do_optimization( .as_ref() .expect("we just checked if `which` returned an err; qed") .as_path(); - log::info!("Path to wasm-opt executable: {}", wasm_opt_path.display()); + tracing::info!("Path to wasm-opt executable: {}", wasm_opt_path.display()); check_wasm_opt_version_compatibility(wasm_opt_path)?; - log::info!( + tracing::info!( "Optimization level passed to wasm-opt: {}", optimization_level ); @@ -631,7 +631,7 @@ fn do_optimization( if keep_debug_symbols { command.arg("-g"); } - log::info!("Invoking wasm-opt with {:?}", command); + tracing::info!("Invoking wasm-opt with {:?}", command); let output = command.output().map_err(|err| { anyhow::anyhow!( "Executing {} failed with {:?}", @@ -727,7 +727,7 @@ fn check_wasm_opt_version_compatibility(wasm_opt_path: &Path) -> Result<()> { ) })?; - log::info!( + tracing::info!( "The wasm-opt version output is '{}', which was parsed to '{}'", version_stdout, version_number @@ -775,7 +775,7 @@ fn assert_compatible_ink_dependencies( /// /// This feature was introduced in `3.0.0-rc4` with `ink_env/ink-debug`. pub fn assert_debug_mode_supported(ink_version: &Version) -> anyhow::Result<()> { - log::info!("Contract version: {:?}", ink_version); + tracing::info!("Contract version: {:?}", ink_version); let minimum_version = Version::parse("3.0.0-rc4").expect("parsing version failed"); if ink_version < &minimum_version { anyhow::bail!( diff --git a/src/cmd/extrinsics/call.rs b/src/cmd/extrinsics/call.rs index 6e074041c..77609ffb4 100644 --- a/src/cmd/extrinsics/call.rs +++ b/src/cmd/extrinsics/call.rs @@ -91,7 +91,7 @@ impl CallCommand { load_metadata(self.extrinsic_opts.manifest_path.as_ref())?; let transcoder = ContractMessageTranscoder::new(&contract_metadata); let call_data = transcoder.encode(&self.message, &self.args)?; - log::debug!("Message data: {:?}", hex::encode(&call_data)); + tracing::debug!("Message data: {:?}", hex::encode(&call_data)); let signer = super::pair_signer(self.extrinsic_opts.signer()?); @@ -168,7 +168,7 @@ impl CallCommand { signer: &PairSigner, transcoder: &ContractMessageTranscoder<'_>, ) -> Result<()> { - log::debug!("calling contract {:?}", self.contract); + tracing::debug!("calling contract {:?}", self.contract); let gas_limit = self .pre_submit_dry_run_gas_estimate(client, data.clone(), signer) diff --git a/src/cmd/extrinsics/events.rs b/src/cmd/extrinsics/events.rs index bc7a55fdb..403031742 100644 --- a/src/cmd/extrinsics/events.rs +++ b/src/cmd/extrinsics/events.rs @@ -61,7 +61,7 @@ pub fn display_events( for event in result.iter() { let event = event?; - log::debug!("displaying event {:?}", event); + tracing::debug!("displaying event {:?}", event); let event_metadata = subxt_metadata.event(event.pallet_index(), event.variant_index())?; @@ -82,7 +82,7 @@ pub fn display_events( event.variant_name(), ) && field.as_ref() == Some(&"data".to_string()) { - log::debug!("event data: {:?}", hex::encode(&event_data)); + tracing::debug!("event data: {:?}", hex::encode(&event_data)); let contract_event = transcoder.decode_contract_event(event_data)?; maybe_println!( verbosity, diff --git a/src/cmd/extrinsics/instantiate.rs b/src/cmd/extrinsics/instantiate.rs index fcce3784e..cb16b0499 100644 --- a/src/cmd/extrinsics/instantiate.rs +++ b/src/cmd/extrinsics/instantiate.rs @@ -142,7 +142,7 @@ impl InstantiateCommand { let verbosity = self.extrinsic_opts.verbosity()?; fn load_code(wasm_path: &Path) -> Result { - log::info!("Contract code path: {}", wasm_path.display()); + tracing::info!("Contract code path: {}", wasm_path.display()); let code = fs::read(&wasm_path) .context(format!("Failed to read from {}", wasm_path.display()))?; Ok(Code::Upload(code.into())) @@ -214,7 +214,7 @@ pub struct Exec<'a> { impl<'a> Exec<'a> { async fn exec(&self, code: Code, dry_run: bool) -> Result<()> { - log::debug!("instantiate data {:?}", self.args.data); + tracing::debug!("instantiate data {:?}", self.args.data); if dry_run { let result = self.instantiate_dry_run(code).await?; match result.result { diff --git a/src/cmd/extrinsics/integration_tests.rs b/src/cmd/extrinsics/integration_tests.rs index f492cfde1..153575271 100644 --- a/src/cmd/extrinsics/integration_tests.rs +++ b/src/cmd/extrinsics/integration_tests.rs @@ -71,7 +71,7 @@ impl ContractsNodeProcess { let mut attempts = 1; let client = loop { thread::sleep(time::Duration::from_secs(1)); - log::info!( + tracing::info!( "Connecting to contracts enabled node, attempt {}/{}", attempts, MAX_ATTEMPTS @@ -102,7 +102,7 @@ impl ContractsNodeProcess { attempts, err ); - log::error!("{}", err); + tracing::error!("{}", err); proc.kill()?; Err(err) } @@ -110,9 +110,9 @@ impl ContractsNodeProcess { } fn kill(&mut self) { - log::info!("Killing contracts node process {}", self.proc.id()); + tracing::info!("Killing contracts node process {}", self.proc.id()); if let Err(err) = self.proc.kill() { - log::error!( + tracing::error!( "Error killing contracts node process {}: {}", self.proc.id(), err @@ -136,7 +136,7 @@ impl ContractsNodeProcess { #[ignore] #[async_std::test] async fn build_upload_instantiate_call() { - env_logger::try_init().ok(); + tracing_subscriber::fmt::init(); let tmp_dir = tempfile::Builder::new() .prefix("cargo-contract.cli.test.") @@ -148,7 +148,7 @@ async fn build_upload_instantiate_call() { .await .expect("Error spawning contracts node"); - log::info!( + tracing::info!( "Creating new contract in temporary directory {}", tmp_dir.path().to_string_lossy() ); @@ -164,13 +164,13 @@ async fn build_upload_instantiate_call() { let mut project_path = tmp_dir.path().to_path_buf(); project_path.push("flipper"); - log::info!("Building contract in {}", project_path.to_string_lossy()); + tracing::info!("Building contract in {}", project_path.to_string_lossy()); cargo_contract(project_path.as_path()) .arg("build") .assert() .success(); - log::info!("Uploading the code to the substrate-contracts-node chain"); + tracing::info!("Uploading the code to the substrate-contracts-node chain"); let output = cargo_contract(project_path.as_path()) .arg("upload") .args(&["--suri", "//Alice"]) @@ -187,7 +187,7 @@ async fn build_upload_instantiate_call() { let code_hash = caps.get(1).unwrap().as_str(); assert_eq!(64, code_hash.len()); - log::info!("Instantiating the contract with code hash `{}`", code_hash); + tracing::info!("Instantiating the contract with code hash `{}`", code_hash); let output = cargo_contract(project_path.as_path()) .arg("instantiate") .args(&["--constructor", "new"]) @@ -222,7 +222,7 @@ async fn build_upload_instantiate_call() { // call the `get` message via rpc to assert that it was set to the initial value call_get_rpc(true); - log::info!("Calling flip on the contract `{}`", contract_account); + tracing::info!("Calling flip on the contract `{}`", contract_account); cargo_contract(project_path.as_path()) .arg("call") .args(&["--message", "flip"]) diff --git a/src/cmd/extrinsics/upload.rs b/src/cmd/extrinsics/upload.rs index da0e0a592..ba18c9f78 100644 --- a/src/cmd/extrinsics/upload.rs +++ b/src/cmd/extrinsics/upload.rs @@ -77,7 +77,7 @@ impl UploadCommand { None => crate_metadata.dest_wasm, }; - log::info!("Contract code path: {}", wasm_path.display()); + tracing::info!("Contract code path: {}", wasm_path.display()); let code = std::fs::read(&wasm_path) .context(format!("Failed to read from {}", wasm_path.display()))?; diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 0e759e9c0..ee8614651 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -330,7 +330,7 @@ mod tests { #[test] fn generate_metadata() { - env_logger::try_init().ok(); + tracing_subscriber::fmt::init(); with_new_contract_project(|manifest_path| { // add optional metadata fields let mut test_manifest = TestContractManifest::new(manifest_path)?; diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index ee13412d0..1171d1972 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -135,7 +135,7 @@ impl CrateMetadata { /// Get the result of `cargo metadata`, together with the root package id. fn get_cargo_metadata(manifest_path: &ManifestPath) -> Result<(CargoMetadata, Package)> { - log::info!( + tracing::info!( "Fetching cargo metadata for {}", manifest_path.as_ref().to_string_lossy() ); diff --git a/src/main.rs b/src/main.rs index 6819209dc..aa091c06f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -473,7 +473,7 @@ enum Command { } fn main() { - env_logger::init(); + tracing_subscriber::fmt::init(); let Opts::Contract(args) = Opts::parse(); match exec(args.cmd) { diff --git a/src/util.rs b/src/util.rs index b9e62d15a..49a7bcd28 100644 --- a/src/util.rs +++ b/src/util.rs @@ -89,7 +89,7 @@ where }); if let Some(path) = working_dir { - log::debug!("Setting cargo working dir to '{}'", path.as_ref().display()); + tracing::debug!("Setting cargo working dir to '{}'", path.as_ref().display()); cmd.current_dir(path); } @@ -107,7 +107,7 @@ where Verbosity::Default => &mut cmd, }; - log::info!("Invoking cargo: {:?}", cmd); + tracing::info!("Invoking cargo: {:?}", cmd); let child = cmd // capture the stdout to return from this function as bytes diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index f5c57b9a7..09c72ce89 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -408,7 +408,7 @@ impl Manifest { let path = PathBuf::from(path_str); if path.is_relative() { let lib_abs = abs_dir.join(path); - log::debug!("Rewriting {} to '{}'", value_id, lib_abs.display()); + tracing::debug!("Rewriting {} to '{}'", value_id, lib_abs.display()); *existing_path = value::Value::String(lib_abs.to_string_lossy().into()) } Ok(()) @@ -433,7 +433,7 @@ impl Manifest { ) } let path = abs_dir.join(default_path); - log::debug!("Adding default path '{}'", path.display()); + tracing::debug!("Adding default path '{}'", path.display()); table.insert( "path".into(), value::Value::String(path.to_string_lossy().into()), @@ -533,7 +533,7 @@ impl Manifest { } let updated_toml = toml::to_string(&self.toml)?; - log::debug!( + tracing::debug!( "Writing updated manifest to '{}'", manifest_path.as_ref().display() ); diff --git a/src/workspace/metadata.rs b/src/workspace/metadata.rs index 6d953254d..2919b5d5b 100644 --- a/src/workspace/metadata.rs +++ b/src/workspace/metadata.rs @@ -34,7 +34,7 @@ pub(super) fn generate_package>( mut ink_metadata_dependency: value::Table, ) -> Result<()> { let dir = target_dir.as_ref(); - log::debug!( + tracing::debug!( "Generating metadata package for {} in {}", contract_package_name, dir.display() diff --git a/src/workspace/mod.rs b/src/workspace/mod.rs index 4808b942f..0695e3c72 100644 --- a/src/workspace/mod.rs +++ b/src/workspace/mod.rs @@ -199,7 +199,7 @@ impl Workspace { let tmp_dir = tempfile::Builder::new() .prefix("cargo-contract_") .tempdir()?; - log::debug!("Using temp workspace at '{}'", tmp_dir.path().display()); + tracing::debug!("Using temp workspace at '{}'", tmp_dir.path().display()); let new_paths = self.write(&tmp_dir)?; let root_manifest_path = new_paths .iter() diff --git a/tests/decode.rs b/tests/decode.rs index 970458d66..ae8652ba8 100644 --- a/tests/decode.rs +++ b/tests/decode.rs @@ -80,7 +80,7 @@ fn decode_works() { .assert() .success(); - log::info!("Building contract in {}", project_dir.to_string_lossy()); + tracing::info!("Building contract in {}", project_dir.to_string_lossy()); cargo_contract(&project_dir) .arg("build") .arg("--skip-linting") diff --git a/transcode/Cargo.toml b/transcode/Cargo.toml index 312e73cca..5f0e37a80 100644 --- a/transcode/Cargo.toml +++ b/transcode/Cargo.toml @@ -26,7 +26,7 @@ indexmap = "1.9.1" ink_env = "3.3" ink_metadata = { version = "3.3", features = ["derive"] } itertools = "0.10.3" -log = "0.4.17" +tracing = "0.1.36" nom = "7.1.1" nom-supreme = { version = "0.7.0", features = ["error"] } scale = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] } diff --git a/transcode/src/decode.rs b/transcode/src/decode.rs index 1654a7448..205bbfc7a 100644 --- a/transcode/src/decode.rs +++ b/transcode/src/decode.rs @@ -66,7 +66,7 @@ impl<'a> Decoder<'a> { let ty = self.registry.resolve(type_id).ok_or_else(|| { anyhow::anyhow!("Failed to resolve type with id `{:?}`", type_id) })?; - log::debug!( + tracing::debug!( "Decoding input with type id `{:?}` and definition `{:?}`", type_id, ty diff --git a/transcode/src/encode.rs b/transcode/src/encode.rs index fe6f221f3..f13121090 100644 --- a/transcode/src/encode.rs +++ b/transcode/src/encode.rs @@ -73,7 +73,7 @@ impl<'a> Encoder<'a> { anyhow::anyhow!("Failed to resolve type with id '{:?}'", type_id) })?; - log::debug!( + tracing::debug!( "Encoding value `{:?}` with type id `{:?}` and definition `{:?}`", value, type_id, diff --git a/transcode/src/env_types.rs b/transcode/src/env_types.rs index b00db1ef6..853c7a0f5 100644 --- a/transcode/src/env_types.rs +++ b/transcode/src/env_types.rs @@ -75,7 +75,7 @@ impl EnvTypesTranscoder { { match self.encoders.get(&type_id) { Some(encoder) => { - log::debug!("Encoding type {:?} with custom encoder", type_id); + tracing::debug!("Encoding type {:?} with custom encoder", type_id); let encoded_env_type = encoder .encode_value(value) .context("Error encoding custom type")?; @@ -96,12 +96,12 @@ impl EnvTypesTranscoder { pub fn try_decode(&self, type_id: u32, input: &mut &[u8]) -> Result> { match self.decoders.get(&type_id) { Some(decoder) => { - log::debug!("Decoding type {:?} with custom decoder", type_id); + tracing::debug!("Decoding type {:?} with custom decoder", type_id); let decoded = decoder.decode_value(input)?; Ok(Some(decoded)) } None => { - log::debug!("No custom decoder found for type {:?}", type_id); + tracing::debug!("No custom decoder found for type {:?}", type_id); Ok(None) } } diff --git a/transcode/src/lib.rs b/transcode/src/lib.rs index 1b882d667..538eb84ee 100644 --- a/transcode/src/lib.rs +++ b/transcode/src/lib.rs @@ -208,7 +208,7 @@ impl<'a> ContractMessageTranscoder<'a> { variant_index ) })?; - log::debug!("Decoding contract event '{}'", event_spec.label()); + tracing::debug!("Decoding contract event '{}'", event_spec.label()); let mut args = Vec::new(); for arg in event_spec.args() { @@ -235,7 +235,7 @@ impl<'a> ContractMessageTranscoder<'a> { hex::encode(&msg_selector) ) })?; - log::debug!("Decoding contract message '{}'", msg_spec.label()); + tracing::debug!("Decoding contract message '{}'", msg_spec.label()); let mut args = Vec::new(); for arg in msg_spec.args() { @@ -262,7 +262,7 @@ impl<'a> ContractMessageTranscoder<'a> { hex::encode(&msg_selector) ) })?; - log::debug!("Decoding contract constructor '{}'", msg_spec.label()); + tracing::debug!("Decoding contract constructor '{}'", msg_spec.label()); let mut args = Vec::new(); for arg in msg_spec.args() { diff --git a/transcode/src/transcoder.rs b/transcode/src/transcoder.rs index dc07bd706..52a3742d1 100644 --- a/transcode/src/transcoder.rs +++ b/transcode/src/transcoder.rs @@ -126,7 +126,7 @@ impl<'a> TranscoderBuilder<'a> { match type_id { Some(type_id) => { let existing = this.encoders.insert(*type_id, Box::new(encoder)); - log::debug!("Registered custom encoder for type `{:?}`", type_id); + tracing::debug!("Registered custom encoder for type `{:?}`", type_id); if existing.is_some() { panic!( "Attempted to register encoder with existing type id {:?}", @@ -136,7 +136,7 @@ impl<'a> TranscoderBuilder<'a> { } None => { // if the type is not present in the registry, it just means it has not been used. - log::info!("No matching type in registry for path {:?}.", path_key); + tracing::info!("No matching type in registry for path {:?}.", path_key); } } this @@ -155,7 +155,7 @@ impl<'a> TranscoderBuilder<'a> { match type_id { Some(type_id) => { let existing = this.decoders.insert(*type_id, Box::new(encoder)); - log::debug!("Registered custom decoder for type `{:?}`", type_id); + tracing::debug!("Registered custom decoder for type `{:?}`", type_id); if existing.is_some() { panic!( "Attempted to register decoder with existing type id {:?}", @@ -165,7 +165,7 @@ impl<'a> TranscoderBuilder<'a> { } None => { // if the type is not present in the registry, it just means it has not been used. - log::info!("No matching type in registry for path {:?}.", path_key); + tracing::info!("No matching type in registry for path {:?}.", path_key); } } this