Просмотр исходного кода

util/cli: change the log path in async_daemonize

ghassmo 4 лет назад
Родитель
Сommit
a6b9620b48
3 измененных файлов с 10 добавлено и 5 удалено
  1. 1 0
      bin/lilith/src/main.rs
  2. 1 0
      script/research/dhtd/src/main.rs
  3. 8 5
      src/util/cli.rs

+ 1 - 0
bin/lilith/src/main.rs

@@ -9,6 +9,7 @@ use darkfi::{
     async_daemonize, net,
     util::{
         cli::{get_log_config, get_log_level, spawn_config},
+        expand_path,
         path::get_config_path,
     },
     Result,

+ 1 - 0
script/research/dhtd/src/main.rs

@@ -24,6 +24,7 @@ use darkfi::{
         cli::{get_log_config, get_log_level, spawn_config},
         path::get_config_path,
         serial::serialize,
+        expand_path,
     },
     Result,
 };

+ 8 - 5
src/util/cli.rs

@@ -126,7 +126,7 @@ macro_rules! cli_desc {
 ///     async_daemonize, cli_desc,
 ///     util::{
 ///         cli::{get_log_config, get_log_level, spawn_config},
-///         path::get_config_path,
+///         path::get_config_path, expand_path
 ///     },
 ///     Result,
 /// };
@@ -165,11 +165,14 @@ macro_rules! async_daemonize {
             let log_level = get_log_level(args.verbose.into());
             let log_config = get_log_config();
 
-            let env_log_file_path = match std::env::var("DARKFI_LOG") {
-                Ok(p) => std::fs::File::create(p).unwrap(),
-                Err(_) => std::fs::File::create("/tmp/darkfi.log").unwrap(),
+            let log_file_path = match std::env::var("DARKFI_LOG") {
+                Ok(p) => p,
+                Err(_) => "~/.local/darkfi.log".into(),
             };
 
+            let log_file_path = expand_path(&log_file_path)?;
+            let log_file = std::fs::File::create(log_file_path)?;
+
             simplelog::CombinedLogger::init(vec![
                 simplelog::TermLogger::new(
                     log_level,
@@ -177,7 +180,7 @@ macro_rules! async_daemonize {
                     simplelog::TerminalMode::Mixed,
                     simplelog::ColorChoice::Auto,
                 ),
-                simplelog::WriteLogger::new(log_level, log_config, env_log_file_path),
+                simplelog::WriteLogger::new(log_level, log_config, log_file),
             ])?;
 
             // https://docs.rs/smol/latest/smol/struct.Executor.html#examples