Skip to content

feat: log to file by default and allow custom log file path#969

Open
kanishka0411 wants to merge 1 commit into
getfloresta:masterfrom
kanishka0411:feat/debug-log-file
Open

feat: log to file by default and allow custom log file path#969
kanishka0411 wants to merge 1 commit into
getfloresta:masterfrom
kanishka0411:feat/debug-log-file

Conversation

@kanishka0411
Copy link
Copy Markdown

Description and Notes

Related to #947

This aligns Floresta logging behavior with Bitcoin Core defaults by enabling file logging by default. Previously, file logging required an explicit flag; now logs are written to <data_dir>/debug.log automatically.

New CLI flags:

  • --debuglogfile= to set a custom log file path (relative paths are prefixed by the net-specific datadir)
  • --nodebuglogfile to disable file logging entirely

How to verify the changes you have done?

  • cargo test -p florestad -p floresta-node
  • cargo run -p florestad -- --network regtest --connect 127.0.0.1:1
  • cargo run -p florestad -- --network regtest --debuglogfile=custom.log --connect 127.0.0.1:1
  • cargo run -p florestad -- --network regtest --nodebuglogfile --connect 127.0.0.1:1

Contributor Checklist

  • I've followed the contribution guidelines
  • I've verified one of the following:
    • Ran just pcc (recommended but slower)
    • Ran just lint-features '-- -D warnings' && cargo test --release
    • Confirmed CI passed on my fork
  • I've linked any related issue(s) in the sections above

Copy link
Copy Markdown

@GideonBature GideonBature left a comment

Choose a reason for hiding this comment

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

tACK

running 7 tests
test tests::test_resolve_debug_log_file_absolute_path ... ok
test tests::test_resolve_debug_log_file_default ... ok
test tests::test_resolve_debug_log_file_disabled ... ok
test tests::test_resolve_debug_log_file_disabled_overrides_custom ... ok
test tests::test_resolve_debug_log_file_network_specific_datadir ... ok
test tests::test_resolve_debug_log_file_relative_path ... ok
test tests::test_resolve_debug_log_file_relative_subdir ... ok

test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

I ran the tests and they all passed. And the solution LGTM.

Comment thread bin/florestad/src/cli.rs
#[arg(long)]
/// Option for saving log into data_Dir
#[arg(long, value_name = "FILE")]
/// Specify location of debug log file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think debug log file is redundant. Just log file is fine

Comment thread bin/florestad/src/main.rs
Comment on lines +192 to +218
/// Resolves the debug log file path from the CLI flags.
///
/// File logging is enabled by default (matching Bitcoin Core). The user can:
/// - Override the path with `--debuglogfile=<path>`
/// - Disable file logging entirely with `--nodebuglogfile`
///
/// Relative paths are prefixed by the net-specific `data_dir`.
/// Returns `None` when file logging is disabled, or `Some(absolute_path)` otherwise.
fn resolve_debug_log_file(
no_debug_log_file: bool,
debug_log_file: Option<&str>,
data_dir: &str,
) -> Option<String> {
if no_debug_log_file {
return None;
}

let raw = debug_log_file.unwrap_or(LOG_FILE);
let path = PathBuf::from(raw);
let absolute = if path.is_absolute() {
path
} else {
PathBuf::from(data_dir).join(path)
};
Some(absolute.to_string_lossy().into_owned())
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can live inside logger.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants