Skip to content

Commit 600ba8c

Browse files
feat(iroh): allow setting the logging directory via config file (#2391)
## Description Adds the options to set the directory where logs will be created in the config file. **Example:** ```toml [file_logs] rust_log = "iroh=info" rotation = "daily" max_files = 1 dir = "/home/me/my_logs" ``` It is recommended that the path is absolute, otherwise it will be interpreted as relative _to the execution dir_. If this option is not set, the default `<IROH_DATA_DIR>/logs` will be used. ## Breaking Changes N/a ## Notes & open questions N/a ## Change checklist - [ ] Self-review. - [ ] Documentation updates if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent eb74cf6 commit 600ba8c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

iroh-cli/src/logging.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub(crate) const DEFAULT_FILE_RUST_LOG: &str = "rustyline=warn,debug";
2020
/// - use the default [`fmt::format::Format`] save for:
2121
/// - including line numbers.
2222
/// - not using ansi colors.
23-
/// - create log files in the `logs` dir inside the given `iroh_data_root`.
23+
/// - create log files in the [`FileLogging::dir`] directory. If not provided, the `logs` dir
24+
/// inside the given `iroh_data_root` is used.
2425
/// - rotate files every [`Self::rotation`].
2526
/// - keep at most [`Self::max_files`] log files.
2627
/// - use the filtering defined by [`Self::rust_log`]. When not provided, the default
@@ -38,6 +39,7 @@ pub(crate) fn init_terminal_and_file_logging(
3839
rust_log,
3940
max_files,
4041
rotation,
42+
dir,
4143
} = file_log_config;
4244

4345
let filter = rust_log.layer();
@@ -51,7 +53,9 @@ pub(crate) fn init_terminal_and_file_logging(
5153
Rotation::Daily => rolling::Rotation::DAILY,
5254
Rotation::Never => rolling::Rotation::NEVER,
5355
};
54-
let logs_path = logs_dir.join("logs");
56+
57+
// prefer the directory set in the config file over the default
58+
let logs_path = dir.clone().unwrap_or_else(|| logs_dir.join("logs"));
5559

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

107113
impl Default for FileLogging {
@@ -110,6 +116,7 @@ impl Default for FileLogging {
110116
rust_log: EnvFilter::default(),
111117
max_files: 4,
112118
rotation: Rotation::default(),
119+
dir: None,
113120
}
114121
}
115122
}

0 commit comments

Comments
 (0)