Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable logging to a file #1856

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ enum-iterator = "2.0"
enumflags2 = "0.7"
expect-test = "1.3"
fallible-iterator = "0.3"
file-rotate = "0.7"
fix-hidden-lifetime-bug = "0.2"
fixed-hash = "0.8"
flate2 = "1.0"
Expand Down
4 changes: 1 addition & 3 deletions node-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

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, false).await?;
let setup_result = node_lib::setup(opts).await?;
match setup_result {
node_lib::NodeSetupResult::Node(node) => {
node.main().await;
Expand Down
29 changes: 18 additions & 11 deletions node-gui/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,37 @@ pub async fn node_initialize(
);
}

let mut opts = node_lib::Options::from_args(std::env::args_os());
opts.command = match network {
InitNetwork::Mainnet => Some(Command::Mainnet(RunOptions::default())),
InitNetwork::Testnet => Some(Command::Testnet(RunOptions::default())),
let opts = {
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 =
opts.command.map_or(RunOptions::default(), |c| c.run_options().clone());
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 {
InitNetwork::Mainnet => Some(Command::Mainnet(run_opts)),
InitNetwork::Testnet => Some(Command::Testnet(run_opts)),
};
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();
let (wallet_updated_tx, wallet_updated_rx) = unbounded_channel();

let (chain_config, chain_info) = match mode {
WalletMode::Hot => {
let setup_result = node_lib::setup(opts, true).await?;
let setup_result = node_lib::setup(opts).await?;
let node = match setup_result {
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
1 change: 1 addition & 0 deletions node-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ utils-networking = { path = "../utils/networking" }

anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
file-rotate.workspace = true
jsonrpsee = { workspace = true, features = ["macros"] }
tokio = { workspace = true, default-features = false }
serde = { workspace = true, features = ["derive"] }
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
#[clap(long, action = clap::ArgAction::Set)]
#[arg(hide = true)]
pub log_to_file: Option<bool>,
Comment on lines +92 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we hide it?

(If not, the description should be more detailed, mentioning that the default value depends on the application and where the logs will be located).


/// 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
Loading