diff options
author | zjp <jiping_zhou@foxmail.com> | 2023-05-13 14:14:36 +0800 |
---|---|---|
committer | Denis Isidoro <denis.isidoro@uber.com> | 2023-12-10 06:26:34 -0300 |
commit | 2933740c1786a6652157bcf492dd4119c21d2195 (patch) | |
tree | fff6cee9e1e3ce25d2d02e8b7c4cdec528e17f81 | |
parent | 6822f1d51bf7b37f1886677ed8dc110af2887da1 (diff) |
If config path doesn't exist, navi won't log.
-rw-r--r-- | src/bin/main.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index fa12d64..8c4856a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -40,10 +40,16 @@ fn init_logger() -> anyhow::Result<()> { let mut file = navi::default_config_pathbuf()?; file.set_file_name(FILE_NAME); + // If config path doesn't exist, navi won't log. + if file.parent().map(|p| !p.exists()).unwrap_or(true) { + return Ok(()); + } + + let writer = std::fs::File::create(&file).with_context(|| format!("{file:?} is not created"))?; tracing::subscriber::set_global_default( tracing_subscriber::fmt() .with_ansi(false) - .with_writer(std::fs::File::create(file)?) + .with_writer(writer) .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .finish(), )?; |