mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
If config path doesn't exist, navi won't log.
This commit is contained in:
parent
6822f1d51b
commit
2933740c17
1 changed files with 7 additions and 1 deletions
|
@ -40,10 +40,16 @@ fn init_logger() -> anyhow::Result<()> {
|
||||||
let mut file = navi::default_config_pathbuf()?;
|
let mut file = navi::default_config_pathbuf()?;
|
||||||
file.set_file_name(FILE_NAME);
|
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::set_global_default(
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_ansi(false)
|
.with_ansi(false)
|
||||||
.with_writer(std::fs::File::create(file)?)
|
.with_writer(writer)
|
||||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||||
.finish(),
|
.finish(),
|
||||||
)?;
|
)?;
|
||||||
|
|
Loading…
Reference in a new issue