Skip to content

Commit

Permalink
Colorize the output (#66)
Browse files Browse the repository at this point in the history
Adds some colors to the logs and also some empty space around the log
lines from try-runtime-cli to make it more clear what belongs to what.
Before I always had the problem that there was a wall of text and I
didn't know when something started and something ended. This pr makes it
a little bit better. The ashetics are discussable and clearly can be
improved.

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
  • Loading branch information
bkchr and liamaharon authored Dec 21, 2023
1 parent 68c3c10 commit 75b4252
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
11 changes: 9 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"
members = ["cli", "core"]

[workspace.package]
version = "0.5.1"
version = "0.5.2"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Substrate's programmatic testing framework."
edition = "2021"
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sp-version = { workspace = true }
sp-weights = { workspace = true }

substrate-rpc-client = { workspace = true }
paris = "1.5.15"

[dev-dependencies]
assert_cmd = { workspace = true }
Expand Down
58 changes: 52 additions & 6 deletions core/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{fmt::Debug, str::FromStr};

use bytesize::ByteSize;
use frame_try_runtime::UpgradeCheckSelect;
use paris::formatter::colorize_string;
use parity_scale_codec::Encode;
use sc_executor::sp_wasm_interface::HostFunctions;
use sp_core::{hexdisplay::HexDisplay, Hasher};
Expand Down Expand Up @@ -101,8 +102,23 @@ where

// Run `TryRuntime_on_runtime_upgrade` with the given checks.
log::info!(
"🔬 Running TryRuntime_on_runtime_upgrade with checks: {:?}",
command.checks
"{}",
colorize_string(
"<bold><blue>-------------------------------------------------------------------\n\n"
)
);
log::info!(
"{}",
colorize_string(format!(
"🔬 <bold><blue>Running TryRuntime_on_runtime_upgrade with checks: {:?}\n\n",
command.checks
))
);
log::info!(
"{}",
colorize_string(
"<bold><blue>-------------------------------------------------------------------"
)
);
// Save the overlayed changes from the first run, so we can use them later for idempotency
// checks.
Expand All @@ -126,7 +142,16 @@ where
UpgradeCheckSelect::None => (proof, ref_time_results),
_ => {
log::info!(
"🔬 TryRuntime_on_runtime_upgrade succeeded! Running it again without checks for weight measurements."
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------\n\n")
);
log::info!(
"{}",
colorize_string("🔬 <bold><blue>TryRuntime_on_runtime_upgrade succeeded! Running it again without checks for weight measurements.\n\n"),
);
log::info!(
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------")
);
let (proof, encoded_result) = state_machine_call_with_proof::<Block, HostFns>(
&ext,
Expand All @@ -150,8 +175,16 @@ where
}
false => {
log::info!(
"🔬 Running TryRuntime_on_runtime_upgrade again to check idempotency: {:?}",
command.checks
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------\n\n")
);
log::info!(
"{}",
colorize_string(format!("🔬 <bold><blue>Running TryRuntime_on_runtime_upgrade again to check idempotency: {:?}\n\n", command.checks)),
);
log::info!(
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------")
);
let (oc_pre_root, _) = overlayed_changes.storage_root(&ext.backend, ext.state_version);
match state_machine_call_with_proof::<Block, HostFns>(
Expand Down Expand Up @@ -213,7 +246,20 @@ where
};

if !weight_ok || !idempotency_ok {
log::error!("❌ Issues detected, exiting non-zero. See logs.");
log::error!(
"{}",
colorize_string("<bold><red>-------------------------------------------------------------------\n\n")
);
log::error!(
"{}",
colorize_string("❌ <bold><red>Issues detected, exiting non-zero. See logs.\n\n"),
);
log::error!(
"{}",
colorize_string(
"<bold><red>-------------------------------------------------------------------"
)
);
std::process::exit(1);
}

Expand Down

0 comments on commit 75b4252

Please sign in to comment.