Skip to content

Commit 226514e

Browse files
authored
Simplify some logging (#83)
1 parent 1ab3387 commit 226514e

3 files changed

Lines changed: 60 additions & 53 deletions

File tree

core/src/commands/on_runtime_upgrade.rs

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ use std::{collections::BTreeMap, fmt::Debug, str::FromStr};
1919

2020
use bytesize::ByteSize;
2121
use frame_try_runtime::UpgradeCheckSelect;
22-
use paris::formatter::colorize_string;
22+
use log::Level;
2323
use parity_scale_codec::Encode;
2424
use sc_executor::sp_wasm_interface::HostFunctions;
2525
use sp_core::{hexdisplay::HexDisplay, Hasher};
2626
use sp_runtime::traits::{Block as BlockT, HashingFor, NumberFor};
2727
use sp_state_machine::{CompactProof, OverlayedChanges, StorageProof};
2828

2929
use crate::{
30-
build_executor,
30+
build_executor, misc,
3131
state::{RuntimeChecks, State},
3232
state_machine_call_with_proof, RefTimeInfo, SharedParams, LOG_TARGET,
3333
};
@@ -106,24 +106,13 @@ where
106106
}
107107

108108
// Run `TryRuntime_on_runtime_upgrade` with the given checks.
109-
log::info!(
110-
"{}",
111-
colorize_string(
112-
"<bold><blue>-------------------------------------------------------------------\n\n"
113-
)
114-
);
115-
log::info!(
116-
"{}",
117-
colorize_string(format!(
118-
"🔬 <bold><blue>Running TryRuntime_on_runtime_upgrade with checks: {:?}\n\n",
109+
misc::basti_log(
110+
Level::Info,
111+
format!(
112+
"🔬 Running TryRuntime_on_runtime_upgrade with checks: {:?}",
119113
command.checks
120-
))
121-
);
122-
log::info!(
123-
"{}",
124-
colorize_string(
125-
"<bold><blue>-------------------------------------------------------------------"
126114
)
115+
.as_str(),
127116
);
128117
// Save the overlayed changes from the first run, so we can use them later for idempotency
129118
// checks.
@@ -146,17 +135,9 @@ where
146135
let (proof, ref_time_results) = match command.checks {
147136
UpgradeCheckSelect::None => (proof, ref_time_results),
148137
_ => {
149-
log::info!(
150-
"{}",
151-
colorize_string("<bold><blue>-------------------------------------------------------------------\n\n")
152-
);
153-
log::info!(
154-
"{}",
155-
colorize_string("🔬 <bold><blue>TryRuntime_on_runtime_upgrade succeeded! Running it again without checks for weight measurements.\n\n"),
156-
);
157-
log::info!(
158-
"{}",
159-
colorize_string("<bold><blue>-------------------------------------------------------------------")
138+
misc::basti_log(
139+
Level::Info,
140+
"🔬 TryRuntime_on_runtime_upgrade succeeded! Running it again without checks for weight measurements.",
160141
);
161142
let (proof, encoded_result) = state_machine_call_with_proof::<Block, HostFns>(
162143
&ext,
@@ -179,17 +160,13 @@ where
179160
true
180161
}
181162
false => {
182-
log::info!(
183-
"{}",
184-
colorize_string("<bold><blue>-------------------------------------------------------------------\n\n")
185-
);
186-
log::info!(
187-
"{}",
188-
colorize_string(format!("🔬 <bold><blue>Running TryRuntime_on_runtime_upgrade again to check idempotency: {:?}\n\n", command.checks)),
189-
);
190-
log::info!(
191-
"{}",
192-
colorize_string("<bold><blue>-------------------------------------------------------------------")
163+
misc::basti_log(
164+
Level::Info,
165+
format!(
166+
"🔬 Running TryRuntime_on_runtime_upgrade again to check idempotency: {:?}",
167+
command.checks
168+
)
169+
.as_str(),
193170
);
194171
let (oc_pre_root, _) = overlayed_changes.storage_root(&ext.backend, ext.state_version);
195172
overlayed_changes.start_transaction();
@@ -267,19 +244,9 @@ where
267244
};
268245

269246
if !weight_ok || !idempotency_ok {
270-
log::error!(
271-
"{}",
272-
colorize_string("<bold><red>-------------------------------------------------------------------\n\n")
273-
);
274-
log::error!(
275-
"{}",
276-
colorize_string("❌ <bold><red>Issues detected, exiting non-zero. See logs.\n\n"),
277-
);
278-
log::error!(
279-
"{}",
280-
colorize_string(
281-
"<bold><red>-------------------------------------------------------------------"
282-
)
247+
misc::basti_log(
248+
Level::Error,
249+
"❌ Issues detected, exiting non-zero. See logs.",
283250
);
284251
std::process::exit(1);
285252
}

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::shared_parameters::SharedParams;
4242

4343
pub mod commands;
4444
pub mod inherent_provider;
45+
mod misc;
4546
mod parse;
4647
pub mod shared_parameters;
4748
pub mod state;

core/src/misc.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use log::{log, Level};
2+
use paris::formatter::colorize_string;
3+
4+
fn level_to_color(level: Level) -> &'static str {
5+
match level {
6+
Level::Info => "blue",
7+
Level::Warn => "yellow",
8+
Level::Error => "red",
9+
_ => "white",
10+
}
11+
}
12+
13+
/// A BIG log that's very difficult to miss.
14+
pub fn basti_log(level: Level, message: &str) {
15+
let color = level_to_color(level);
16+
log!(
17+
level,
18+
"{}",
19+
colorize_string(format!(
20+
"<bold><{}>{}\n\n",
21+
&color,
22+
"-".repeat(message.len())
23+
))
24+
);
25+
log!(
26+
level,
27+
"{}",
28+
colorize_string(format!("<bold><{}>{}\n\n", &color, message))
29+
);
30+
log!(
31+
level,
32+
"{}",
33+
colorize_string(format!(
34+
"<bold><{}>{}\n\n",
35+
&color,
36+
"-".repeat(message.len())
37+
))
38+
);
39+
}

0 commit comments

Comments
 (0)