Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace log/env_logger with tracing/tracing_subscriber #689

Merged
merged 4 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 28 additions & 14 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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
})
};
Expand Down Expand Up @@ -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
);
Expand All @@ -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 {:?}",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?);

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/extrinsics/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl InstantiateCommand {
let verbosity = self.extrinsic_opts.verbosity()?;

fn load_code(wasm_path: &Path) -> Result<Code> {
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()))
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/cmd/extrinsics/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,17 +102,17 @@ impl ContractsNodeProcess {
attempts,
err
);
log::error!("{}", err);
tracing::error!("{}", err);
proc.kill()?;
Err(err)
}
}
}

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
Expand All @@ -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.")
Expand All @@ -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()
);
Expand All @@ -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"])
Expand All @@ -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"])
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))?;

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
Loading