fix(log): Only show the Zebra logo & intro for the `start` command (#7075)
* Only show the intro for the `start` command * Also disable the log file intro text
This commit is contained in:
parent
5324e5afd2
commit
6311cfbfb3
|
|
@ -422,6 +422,7 @@ impl Application for ZebradApp {
|
||||||
components.push(Box::new(Tracing::new(
|
components.push(Box::new(Tracing::new(
|
||||||
config.network.network,
|
config.network.network,
|
||||||
tracing_config,
|
tracing_config,
|
||||||
|
command.cmd().uses_intro(),
|
||||||
)?));
|
)?));
|
||||||
|
|
||||||
// Log git metadata and platform info when zebrad starts up
|
// Log git metadata and platform info when zebrad starts up
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,26 @@ impl ZebradCmd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if this command shows the Zebra intro logo and text.
|
||||||
|
///
|
||||||
|
/// For example, `Start` acts as a Zcash node.
|
||||||
|
pub(crate) fn uses_intro(&self) -> bool {
|
||||||
|
// List all the commands, so new commands have to make a choice here
|
||||||
|
match self {
|
||||||
|
// Commands that need an intro
|
||||||
|
Start(_) => true,
|
||||||
|
|
||||||
|
// Utility commands
|
||||||
|
CopyState(_) | Download(_) | Generate(_) | TipHeight(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if this command should ignore errors when
|
||||||
|
/// attempting to load a config file.
|
||||||
|
pub(crate) fn should_ignore_load_config_error(&self) -> bool {
|
||||||
|
matches!(self, ZebradCmd::Generate(_) | ZebradCmd::Download(_))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the default log level for this command, based on the `verbose` command line flag.
|
/// Returns the default log level for this command, based on the `verbose` command line flag.
|
||||||
///
|
///
|
||||||
/// Some commands need to be quiet by default.
|
/// Some commands need to be quiet by default.
|
||||||
|
|
@ -87,12 +107,6 @@ impl ZebradCmd {
|
||||||
"debug"
|
"debug"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this command should ignore errors when
|
|
||||||
/// attempting to load a config file.
|
|
||||||
pub(crate) fn should_ignore_load_config_error(&self) -> bool {
|
|
||||||
matches!(self, ZebradCmd::Generate(_) | ZebradCmd::Download(_))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Runnable for ZebradCmd {
|
impl Runnable for ZebradCmd {
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,12 @@ pub struct Tracing {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tracing {
|
impl Tracing {
|
||||||
/// Try to create a new [`Tracing`] component with the given `filter`.
|
/// Try to create a new [`Tracing`] component with the given `config`.
|
||||||
|
///
|
||||||
|
/// If `uses_intro` is true, show a welcome message, the `network`,
|
||||||
|
/// and the Zebra logo on startup. (If the terminal supports it.)
|
||||||
#[allow(clippy::print_stdout, clippy::print_stderr, clippy::unwrap_in_result)]
|
#[allow(clippy::print_stdout, clippy::print_stderr, clippy::unwrap_in_result)]
|
||||||
pub fn new(network: Network, config: Config) -> Result<Self, FrameworkError> {
|
pub fn new(network: Network, config: Config, uses_intro: bool) -> Result<Self, FrameworkError> {
|
||||||
// Only use color if tracing output is being sent to a terminal or if it was explicitly
|
// Only use color if tracing output is being sent to a terminal or if it was explicitly
|
||||||
// forced to.
|
// forced to.
|
||||||
let use_color = config.use_color_stdout();
|
let use_color = config.use_color_stdout();
|
||||||
|
|
@ -76,6 +79,8 @@ impl Tracing {
|
||||||
let filter = config.filter.unwrap_or_default();
|
let filter = config.filter.unwrap_or_default();
|
||||||
let flame_root = &config.flamegraph;
|
let flame_root = &config.flamegraph;
|
||||||
|
|
||||||
|
// Only show the intro for user-focused node server commands like `start`
|
||||||
|
if uses_intro {
|
||||||
// If it's a terminal and color escaping is enabled: clear screen and
|
// If it's a terminal and color escaping is enabled: clear screen and
|
||||||
// print Zebra logo (here `use_color` is being interpreted as
|
// print Zebra logo (here `use_color` is being interpreted as
|
||||||
// "use escape codes")
|
// "use escape codes")
|
||||||
|
|
@ -94,10 +99,15 @@ impl Tracing {
|
||||||
network.lowercase_name(),
|
network.lowercase_name(),
|
||||||
build_version()
|
build_version()
|
||||||
);
|
);
|
||||||
eprintln!("You're helping to strengthen the network and contributing to a social good :)");
|
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() {
|
let writer = if let Some(log_file) = config.log_file.as_ref() {
|
||||||
|
if uses_intro {
|
||||||
println!("running zebra");
|
println!("running zebra");
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the directory for the log file exists.
|
// Make sure the directory for the log file exists.
|
||||||
// If the log is configured in the current directory, it won't have a parent directory.
|
// If the log is configured in the current directory, it won't have a parent directory.
|
||||||
|
|
@ -122,7 +132,9 @@ impl Tracing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if uses_intro {
|
||||||
println!("sending logs to {log_file:?}...");
|
println!("sending logs to {log_file:?}...");
|
||||||
|
}
|
||||||
let log_file = File::options().append(true).create(true).open(log_file)?;
|
let log_file = File::options().append(true).create(true).open(log_file)?;
|
||||||
Box::new(log_file) as BoxWrite
|
Box::new(log_file) as BoxWrite
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue