print a Zebra logo and some text if stderr is terminal (#6945)
* print a Zebra logo and some text in progress bar mode * add network to printed line, add heart to logo * print logo and message regardless of progress-bar; document how logo was generated
This commit is contained in:
parent
015a970e16
commit
3af03c3971
|
@ -419,7 +419,10 @@ impl Application for ZebradApp {
|
|||
tracing_config.filter = Some(default_filter.to_owned());
|
||||
tracing_config.flamegraph = None;
|
||||
}
|
||||
components.push(Box::new(Tracing::new(tracing_config)?));
|
||||
components.push(Box::new(Tracing::new(
|
||||
config.network.network,
|
||||
tracing_config,
|
||||
)?));
|
||||
|
||||
// Log git metadata and platform info when zebrad starts up
|
||||
if is_server {
|
||||
|
|
|
@ -138,6 +138,12 @@ impl Config {
|
|||
self.force_use_color || (self.use_color && atty::is(atty::Stream::Stdout))
|
||||
}
|
||||
|
||||
/// Returns `true` if standard error should use color escapes.
|
||||
/// Automatically checks if Zebra is running in a terminal.
|
||||
pub fn use_color_stderr(&self) -> bool {
|
||||
self.force_use_color || (self.use_color && atty::is(atty::Stream::Stderr))
|
||||
}
|
||||
|
||||
/// Returns `true` if output that could go to standard output or standard error
|
||||
/// should use color escapes. Automatically checks if Zebra is running in a terminal.
|
||||
pub fn use_color_stdout_and_stderr(&self) -> bool {
|
||||
|
|
|
@ -15,12 +15,26 @@ use tracing_subscriber::{
|
|||
util::SubscriberInitExt,
|
||||
EnvFilter,
|
||||
};
|
||||
use zebra_chain::parameters::Network;
|
||||
|
||||
use crate::{application::build_version, components::tracing::Config};
|
||||
|
||||
#[cfg(feature = "flamegraph")]
|
||||
use super::flame;
|
||||
|
||||
// Art generated with these two images.
|
||||
// Zebra logo: book/theme/favicon.png
|
||||
// Heart image: https://commons.wikimedia.org/wiki/File:Heart_coraz%C3%B3n.svg
|
||||
// (License: CC BY-SA 3.0)
|
||||
//
|
||||
// How to render
|
||||
//
|
||||
// Convert heart image to PNG (2000px) and run:
|
||||
// img2txt -W 40 -H 20 -f utf8 -d none Heart_corazón.svg.png > heart.utf8
|
||||
// img2txt -W 40 -H 20 -f utf8 -d none favicon.png > logo.utf8
|
||||
// paste favicon.utf8 heart.utf8 > zebra.utf8
|
||||
static ZEBRA_ART: [u8; include_bytes!("zebra.utf8").len()] = *include_bytes!("zebra.utf8");
|
||||
|
||||
/// A type-erased boxed writer that can be sent between threads safely.
|
||||
pub type BoxWrite = Box<dyn Write + Send + Sync + 'static>;
|
||||
|
||||
|
@ -52,15 +66,36 @@ pub struct Tracing {
|
|||
|
||||
impl Tracing {
|
||||
/// Try to create a new [`Tracing`] component with the given `filter`.
|
||||
#[allow(clippy::print_stdout, clippy::print_stderr)]
|
||||
pub fn new(config: Config) -> Result<Self, FrameworkError> {
|
||||
#[allow(clippy::print_stdout, clippy::print_stderr, clippy::unwrap_in_result)]
|
||||
pub fn new(network: Network, config: Config) -> Result<Self, FrameworkError> {
|
||||
// Only use color if tracing output is being sent to a terminal or if it was explicitly
|
||||
// forced to.
|
||||
let use_color = config.use_color_stdout();
|
||||
let use_color_stderr = config.use_color_stderr();
|
||||
|
||||
let filter = config.filter.unwrap_or_default();
|
||||
let flame_root = &config.flamegraph;
|
||||
|
||||
// If it's a terminal and color escaping is enabled: clear screen and
|
||||
// print Zebra logo (here `use_color` is being interpreted as
|
||||
// "use escape codes")
|
||||
if use_color_stderr {
|
||||
// Clear screen
|
||||
eprint!("\x1B[2J");
|
||||
eprintln!(
|
||||
"{}",
|
||||
std::str::from_utf8(&ZEBRA_ART)
|
||||
.expect("should always work on a UTF-8 encoded constant")
|
||||
);
|
||||
}
|
||||
|
||||
eprintln!(
|
||||
"Thank you for running a {} zebrad {} node!",
|
||||
network.lowercase_name(),
|
||||
build_version()
|
||||
);
|
||||
eprintln!("You're helping to strengthen the network and contributing to a social good :)");
|
||||
|
||||
let writer = if let Some(log_file) = config.log_file.as_ref() {
|
||||
println!("running zebra");
|
||||
|
||||
|
@ -263,10 +298,6 @@ impl Tracing {
|
|||
howudoin::init(terminal_consumer);
|
||||
|
||||
info!("activated progress bar");
|
||||
|
||||
if config.log_file.is_some() {
|
||||
eprintln!("waiting for initial progress reports...");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
[0;1;30;90;43mX@8[0;1;33;93;43m:::::::[0;1;30;90;43m@X[0m
|
||||
[0;1;30;90;43m@[0;1;33;93;43m::[0;37;43mX[0;1;33;93;43m:;[0;1;37;97;47mS[0;1;33;93;47mX[0;1;33;93;43m;[0;1;37;97;47m%8[0;37;43mS[0;33;47m8[0;1;37;97;47m@[0;37;43m@[0;1;33;93;43m:[0;37;43mX[0;1;33;93;43m::[0;1;30;90;43m8[0m
|
||||
[0;1;30;90;43m@[0;1;33;93;43m:;[0;1;33;93;47m@[0;33;47m8[0;37;43m@[0;37;5;47;107m.S8 ;;t;. XX.[0;1;37;97;47m;[0;37;43m@[0;1;33;93;47m@[0;1;33;93;43m;:[0;1;30;90;43m@[0m [0;1;31;91;41m8[0;31;5;41;101m; %[0;1;31;91;41mX[0m [0;1;31;91;41mX[0;31;5;41;101m% ;[0;1;31;91;41m8[0m
|
||||
[0;1;30;90;43m8[0;1;33;93;43m:[0;37;43m@[0;33;47m88[0;37;5;47;107m .%@.[0;1;33;93;47mS@[0;37;5;47;107m.XS: [0;33;47m888[0;1;33;93;43m:[0;1;30;90;43m8[0m [0;1;31;91;41mX[0;31;5;41;101m :[0;1;31;91;41m:[0m [0;1;31;91;41m.[0;31;5;41;101m: [0;1;31;91;41mX[0m
|
||||
[0;1;33;93;43m:;[0;37;43mS[0;1;33;93;47mX[0;37;5;47;107m X[0;1;37;97;47mS[0;33;47m8[0;1;33;93;43m;::[0;37;43m@[0;1;37;97;47mX@[0;33;47m8[0;1;33;93;43m::;[0;33;47m8[0;1;37;97;47mt[0;37;5;47;107m8: [0;1;37;97;47m8[0;1;33;93;43m;;:[0;1;30;90;43m@[0m [0;31;5;41;101m% SS %[0m
|
||||
[0;1;30;90;43m@[0;1;33;93;43m::[0;1;37;97;47m@[0;37;5;47;107m [0;1;37;97;47m8[0;33;47m8[0;1;33;93;43m:::[0;33;47m8[0;1;30;90;47m [0;1;30;90;43m8[0;1;33;93;43m::[0;1;30;90;43m88[0;1;33;93;43m::::::[0;37;43mX[0;1;37;97;47m@[0;37;5;47;107m 8[0;1;33;93;43m::[0;1;30;90;43m8[0m [0;1;31;91;41mS[0;31;5;41;101m [0;1;31;91;41mX[0m
|
||||
[0;1;30;90;43m@[0;1;33;93;43m:[0;37;43mX[0;1;37;97;47mS8[0;37;5;47;107m [0;1;37;97;47m;[0;1;33;93;43m::::::[0;1;30;90;47m8[0;31;40m.[0;33;5;40;100m8[0;33;47m8[0;31;40m%[0;1;30;90;40m8[0;1;37;97;47m@[0;37;5;47;107mS[0;37;43m8[0;1;30;90;43m8[0;1;33;93;43m::::[0;1;33;93;47m8[0;37;5;47;107m: 8[0;1;37;97;47mS[0;33;47m8[0;1;33;93;43m:[0;1;30;90;43m8[0m [0;31;5;41;101mX S[0m
|
||||
[0;1;33;93;43m::;[0;1;37;97;47m8[0;37;5;47;107m t[0;1;37;97;47m8[0;37;5;47;107mS[0;1;33;93;47m8[0;1;33;93;43m::::[0;1;30;90;43m@[0;1;37;97;47mS[0;1;30;90;47mt[0;34;40m [0;1;30;90;40m88S[0;1;37;97;47mX[0;37;5;47;107m [0;1;37;97;47m@[0;1;30;90;40mS[0;33;5;40;100mS[0;37;5;47;107m@[0;1;37;97;47m8[0;33;5;40;100m:[0;1;30;90;43m8[0;1;33;93;47mS[0;37;5;47;107m;[0;1;37;97;47m8[0;37;5;47;107mS @[0;37;43m@[0;1;33;93;43m::[0m [0;1;31;91;41m8[0;31;5;41;101m 8[0m
|
||||
[0;1;30;90;43m8[0;1;33;93;43m:[0;37;43mX[0;37;5;47;107mX %[0;1;37;97;47m%[0;37;5;47;107m@[0;1;37;97;47m@[0;1;33;93;43m::[0;37;43mX[0;33;5;40;100m%[0;34;40m [0;37;5;47;107m8[0;1;30;90;47m:[0;34;40m [0;1;30;90;40mX[0;37;5;47;107m@ [0;1;37;97;47mt[0;34;40m:[0;30;5;40;100m8[0;37;5;47;107mt [0;1;30;90;47mX[0;34;40m [0;33;5;40;100m.[0;37;5;47;107m.%[0;1;37;97;47mt[0;37;5;47;107m8 ;[0;1;33;93;47m8[0;1;33;93;43m:[0;1;30;90;43m8[0m [0;31;5;41;101m [0m
|
||||
[0;1;33;93;43m::[0;37;43m8[0;1;37;97;47mt[0;37;5;47;107m: [0;1;37;97;47mt[0;37;43mX[0;1;33;93;43m:[0;37;43mX[0;33;47m8[0;33;5;40;100mt[0;1;30;90;40mS[0;34;40m [0;37;5;47;107m8[0;1;30;90;47m:[0;34;40m :[0;1;37;97;47m@[0;37;5;47;107m [0;1;30;90;47m;[0;34;40m.[0;1;30;90;40m8[0;37;5;47;107m@.[0;37;5;40;100mX[0;34;40m [0;36;5;40;100mt[0;37;5;47;107mt8[0;30;5;40;100m8[0;37;5;40;100m8[0;37;5;47;107m: [0;1;37;97;47m@[0;33;47m8[0;1;33;93;43m::[0m [0;31;5;41;101m@ X[0m
|
||||
[0;1;33;93;43m::[0;33;47m8[0;1;37;97;47mS[0;37;5;47;107m: [0;1;33;93;47m@[0;1;33;93;43m:[0;1;30;90;43m8[0;1;30;90;47mXtt[0;36;5;40;100m%[0;34;40m [0;37;5;47;107m8[0;1;30;90;47m:[0;34;40m [0;30;5;40;100mS[0;37;5;47;107m [0;1;30;90;47m8[0;34;40m [0;30;5;40;100m8[0;37;5;47;107mS.[0;36;5;40;100m [0;34;40m [0;36;5;40;100m [0;37;5;47;107m.8[0;34;40m;:[0;1;37;97;47m:[0;37;5;47;107m. [0;1;37;97;47m8[0;1;33;93;47m8[0;1;33;93;43m::[0m [0;31;5;41;101m8 8[0m
|
||||
[0;1;33;93;43m::[0;37;43mX[0;37;5;47;107m8 [0;1;30;90;47mS[0;31;40m@[0;1;30;90;40m8[0;36;5;40;100m [0;1;30;90;40m8[0;31;40m:[0;1;37;97;47m8[0;1;30;90;47m.[0;31;5;40;100m@[0;1;30;90;43m8[0;33;47m@[0;31;40m8[0;30;5;40;100mX[0;37;5;47;107mt [0;37;5;40;100mS[0;34;40m [0;36;5;40;100m [0;37;5;47;107m.%[0;1;30;90;40m8[0;34;40m;[0;1;37;97;47mS[0;37;5;47;107m %[0;1;33;93;47m8[0;1;33;93;43m::[0m [0;31;5;41;101m: :[0m
|
||||
[0;1;33;93;43m::[0;37;43m@[0;1;37;97;47m8[0;37;5;47;107m [0;30;5;40;100mS[0;34;40m .[0;36;5;40;100m [0;1;30;90;47m [0;37;43m@[0;1;33;93;43m:::::::[0;1;33;93;47mX[0;37;5;47;107m;[0;37;5;40;100m@[0;34;40m [0;1;30;90;47m8[0;37;5;47;107m.8[0;1;30;90;40m8S[0;1;37;97;47m8[0;37;5;47;107m @[0;33;47m8[0;1;33;93;43m;:[0;1;30;90;43mX[0m [0;1;31;91;41m:[0;31;5;41;101m: :[0;1;31;91;41m;[0m
|
||||
[0;1;30;90;43m8[0;1;33;93;43m:[0;37;43mX[0;1;37;97;47m8[0;37;5;47;107mX .[0;1;37;97;47m@[0;1;30;90;47m:[0;1;30;90;43mX[0;33;5;40;100m8[0;1;30;90;43m8[0;1;33;93;43m:::::::::[0;1;30;90;43m8[0;31;40m8[0;37;5;40;100m8[0;37;5;47;107m [0;1;37;97;47m@[0;34;40m;:[0;1;37;97;47mX[0;37;5;47;107m %[0;1;37;97;47m8[0;33;47m8[0;1;33;93;43m::[0m [0;31;5;41;101mt t[0m
|
||||
[0;1;30;90;43m@[0;1;33;93;43m::[0;1;37;97;47mS[0;37;5;47;107m 8[0;1;37;97;47m88[0;37;5;47;107m@[0;33;47m8[0;1;33;93;43m:::::::::[0;1;37;97;47m8X; 8[0;37;5;47;107m [0;1;37;97;47m8[0;1;33;93;43m::[0;1;30;90;43m8[0m [0;31;5;41;101m8 8[0m
|
||||
[0;1;30;90;43mX[0;1;33;93;43m:;[0;37;43mS[0;1;33;93;47m@[0;37;5;47;107m [0;1;37;97;47mt[0;37;43mX[0;37;5;47;107mX[0;1;37;97;47m8[0;1;33;93;43m;::::::::[0;37;43mS[0;1;37;97;47m:[0;37;5;47;107m:[0;37;43m@[0;33;47m8[0;37;5;47;107m [0;1;37;97;47m8[0;1;33;93;43m;[0;37;43mS[0;1;33;93;43m:[0;1;30;90;43m8[0m [0;1;31;91;41mX[0;31;5;41;101m. .[0;1;31;91;41mX[0m
|
||||
[0;1;33;93;43m::[0;33;47m8[0;1;33;93;47mS@[0;37;5;47;107m :S8[0;1;37;97;47m8XX@8[0;37;5;47;107mX: [0;1;33;93;47m@XX[0;1;33;93;43m::[0m [0;1;31;91;41m:[0;31;5;41;101m: :[0;1;31;91;41m:[0m
|
||||
[0;1;30;90;43m8[0;1;33;93;43m:;[0;1;37;97;47m%[0;1;33;93;47mX8[0;37;5;47;107m.:S t; [0;1;37;97;47mX[0;1;33;93;47m8[0;1;37;97;47m%[0;37;43mS[0;1;33;93;43m:[0;1;30;90;43m8X[0m [0;31;5;41;101mtt[0m
|
||||
[0;1;30;90;43mX8[0;1;33;93;43m::[0;33;47m8[0;37;43mSS[0;1;37;97;47m8S[0;37;43mX[0;1;37;97;47m8[0;37;5;47;107m@[0;37;43m@[0;1;33;93;47mX[0;37;5;47;107m@[0;33;47m8[0;1;33;93;43m;[0;33;47m8[0;37;43mS[0;1;33;93;43m:[0;1;30;90;43m8X[0m
|
||||
[0;1;30;90;43mX@8[0;1;33;93;43m:::::::[0;1;30;90;43m@XS[0m
|
Loading…
Reference in New Issue