Skip to content

Commit

Permalink
Init logging to file
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Dec 19, 2024
1 parent f13b782 commit 68dcd2a
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 264 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions node-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

pub async fn run() -> anyhow::Result<()> {
let opts = node_lib::Options::from_args(std::env::args_os());
logging::init_logging();
logging::log::info!("Command line options: {opts:?}");
let setup_result = node_lib::setup(opts).await?;
match setup_result {
node_lib::NodeSetupResult::Node(node) => {
Expand Down
9 changes: 3 additions & 6 deletions node-gui/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ pub async fn node_initialize(
let mut opts = node_lib::Options::from_args(std::env::args_os());
let run_opts = {
// For the GUI, we configure different defaults, such as disabling RPC server binding
// and enabling logging to a file.
let mut run_opts = RunOptions::default();
run_opts.rpc_enabled = Some(run_opts.rpc_enabled.unwrap_or(false));
run_opts.log_to_file = Some(run_opts.log_to_file.unwrap_or(true));
run_opts
};
opts.command = match network {
Expand All @@ -135,9 +137,6 @@ pub async fn node_initialize(
opts
};

logging::init_logging();
logging::log::info!("Command line options: {opts:?}");

let (request_tx, request_rx) = unbounded_channel();
let (event_tx, event_rx) = unbounded_channel();
let (low_priority_event_tx, low_priority_event_rx) = unbounded_channel();
Expand All @@ -150,9 +149,7 @@ pub async fn node_initialize(
node_lib::NodeSetupResult::Node(node) => node,
node_lib::NodeSetupResult::DataDirCleanedUp => {
// TODO: find more friendly way to report the message and shut down GUI
anyhow::bail!(
"Data directory is now clean. Please restart the node without `--clean-data` flag"
);
anyhow::bail!("Data directory is now clean. Please restart the node without `--clean-data` flag");
}
};

Expand Down
14 changes: 14 additions & 0 deletions node-lib/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ pub enum Command {
Regtest(Box<RegtestOptions>),
}

impl Command {
pub fn run_options(&self) -> &RunOptions {
match self {
Command::Mainnet(run_options) | Command::Testnet(run_options) => run_options,
Command::Regtest(regtest_options) => &regtest_options.run_options,
}
}
}

#[derive(Args, Clone, Debug)]
pub struct RegtestOptions {
#[clap(flatten)]
Expand All @@ -80,6 +89,11 @@ pub struct RunOptions {
#[clap(long, short, action = clap::ArgAction::SetTrue)]
pub clean_data: Option<bool>,

/// Log to a file instead of stdout
#[clap(long, action = clap::ArgAction::SetTrue)]
#[arg(hide = true)]
pub log_to_file: Option<bool>,

/// Minimum number of connected peers to enable block production.
#[clap(long, value_name = "COUNT")]
pub blockprod_min_peers_to_produce_blocks: Option<usize>,
Expand Down
Loading

0 comments on commit 68dcd2a

Please sign in to comment.