Skip to content

Commit

Permalink
extract set_log_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau committed Feb 5, 2025
1 parent 6972d47 commit c8c86d3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
13 changes: 1 addition & 12 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,18 +1817,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.subcommand(SubCommand::with_name("run").about("Run the validator"))
.subcommand(commands::plugin::command(default_args))
.subcommand(commands::set_identity::command(default_args))
.subcommand(
SubCommand::with_name("set-log-filter")
.about("Adjust the validator log filter")
.arg(
Arg::with_name("filter").takes_value(true).index(1).help(
"New filter using the same format as the RUST_LOG environment variable",
),
)
.after_help(
"Note: the new filter only applies to the currently running validator instance",
),
)
.subcommand(commands::set_log_filter::command(default_args))
.subcommand(commands::staked_nodes_overrides::command(default_args))
.subcommand(commands::wait_for_restart_window::command(default_args))
.subcommand(
Expand Down
1 change: 1 addition & 0 deletions validator/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pub mod exit;
pub mod monitor;
pub mod plugin;
pub mod set_identity;
pub mod set_log_filter;
pub mod staked_nodes_overrides;
pub mod wait_for_restart_window;
28 changes: 28 additions & 0 deletions validator/src/commands/set_log_filter/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use {
crate::{admin_rpc_service, cli::DefaultArgs},
clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand},
std::{path::Path, process::exit},
};

pub fn command(_default_args: &DefaultArgs) -> App<'_, '_> {
SubCommand::with_name("set-log-filter")
.about("Adjust the validator log filter")
.arg(
Arg::with_name("filter")
.takes_value(true)
.index(1)
.help("New filter using the same format as the RUST_LOG environment variable"),
)
.after_help("Note: the new filter only applies to the currently running validator instance")
}

pub fn execute(matches: &ArgMatches, ledger_path: &Path) {
let filter = value_t_or_exit!(matches, "filter", String);
let admin_client = admin_rpc_service::connect(ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.set_log_filter(filter).await })
.unwrap_or_else(|err| {
println!("set log filter failed: {err}");
exit(1);
});
}
9 changes: 1 addition & 8 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,7 @@ pub fn main() {
return;
}
("set-log-filter", Some(subcommand_matches)) => {
let filter = value_t_or_exit!(subcommand_matches, "filter", String);
let admin_client = admin_rpc_service::connect(&ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.set_log_filter(filter).await })
.unwrap_or_else(|err| {
println!("set log filter failed: {err}");
exit(1);
});
commands::set_log_filter::execute(subcommand_matches, &ledger_path);
return;
}
("wait-for-restart-window", Some(subcommand_matches)) => {
Expand Down

0 comments on commit c8c86d3

Please sign in to comment.