Skip to content

feat(iroh): allow setting the logging directory via config file #2391

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

Merged
merged 2 commits into from
Jun 21, 2024
Merged
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
11 changes: 9 additions & 2 deletions iroh-cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub(crate) const DEFAULT_FILE_RUST_LOG: &str = "rustyline=warn,debug";
/// - use the default [`fmt::format::Format`] save for:
/// - including line numbers.
/// - not using ansi colors.
/// - create log files in the `logs` dir inside the given `iroh_data_root`.
/// - create log files in the [`FileLogging::dir`] directory. If not provided, the `logs` dir
/// inside the given `iroh_data_root` is used.
/// - rotate files every [`Self::rotation`].
/// - keep at most [`Self::max_files`] log files.
/// - use the filtering defined by [`Self::rust_log`]. When not provided, the default
Expand All @@ -38,6 +39,7 @@ pub(crate) fn init_terminal_and_file_logging(
rust_log,
max_files,
rotation,
dir,
} = file_log_config;

let filter = rust_log.layer();
Expand All @@ -51,7 +53,9 @@ pub(crate) fn init_terminal_and_file_logging(
Rotation::Daily => rolling::Rotation::DAILY,
Rotation::Never => rolling::Rotation::NEVER,
};
let logs_path = logs_dir.join("logs");

// prefer the directory set in the config file over the default
let logs_path = dir.clone().unwrap_or_else(|| logs_dir.join("logs"));

let file_appender = rolling::Builder::new()
.rotation(rotation)
Expand Down Expand Up @@ -102,6 +106,8 @@ pub(crate) struct FileLogging {
pub(crate) max_files: usize,
/// How often should a new log file be produced.
pub(crate) rotation: Rotation,
/// Where to store log files.
pub(crate) dir: Option<std::path::PathBuf>,
}

impl Default for FileLogging {
Expand All @@ -110,6 +116,7 @@ impl Default for FileLogging {
rust_log: EnvFilter::default(),
max_files: 4,
rotation: Rotation::default(),
dir: None,
}
}
}
Expand Down
Loading