summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-07-13 16:20:46 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-07-13 16:20:46 +0200
commit814286bda8dd55c8953b3ac7271abbb525966052 (patch)
tree50fcb265abe3172ff26165007fd02cfbe84e3acf
parentf5a69fb98a891107522fb9507cc3d98de5551325 (diff)
downloadmullvadvpn-814286bda8dd55c8953b3ac7271abbb525966052.tar.xz
mullvadvpn-814286bda8dd55c8953b3ac7271abbb525966052.zip
Accept path to log file as argument
-rw-r--r--mullvad_daemon/src/cli.rs9
-rw-r--r--mullvad_daemon/src/main.rs8
2 files changed, 13 insertions, 4 deletions
diff --git a/mullvad_daemon/src/cli.rs b/mullvad_daemon/src/cli.rs
index cdc2f5fd81..a5fefcc782 100644
--- a/mullvad_daemon/src/cli.rs
+++ b/mullvad_daemon/src/cli.rs
@@ -1,8 +1,11 @@
use clap::{App, Arg};
use log;
+use std::path::PathBuf;
+
pub struct Config {
pub log_level: log::LogLevelFilter,
+ pub log_file: PathBuf,
}
pub fn get_config() -> Config {
@@ -14,9 +17,11 @@ pub fn get_config() -> Config {
1 => log::LogLevelFilter::Debug,
_ => log::LogLevelFilter::Trace,
};
+ let log_file = PathBuf::from(value_t_or_exit!(matches, "log_file", String));
Config {
log_level,
+ log_file,
}
}
@@ -29,4 +34,8 @@ fn create_app() -> App<'static, 'static> {
.short("v")
.multiple(true)
.help("Sets the level of verbosity."))
+ .arg(Arg::with_name("log_file")
+ .long("log")
+ .default_value("./mullvadd.log")
+ .help("Sets the path where to write the log"))
}
diff --git a/mullvad_daemon/src/main.rs b/mullvad_daemon/src/main.rs
index a9f3dcc460..3736f87c7c 100644
--- a/mullvad_daemon/src/main.rs
+++ b/mullvad_daemon/src/main.rs
@@ -33,6 +33,7 @@ use management_interface::{ManagementInterfaceServer, TunnelCommand};
use mullvad_types::states::{DaemonState, SecurityState, TargetState};
use std::io;
+use std::path::Path;
use std::sync::{Arc, Mutex, mpsc};
use std::thread;
@@ -457,7 +458,7 @@ quick_main!(run);
fn run() -> Result<()> {
let config = cli::get_config();
- init_logger(config.log_level)?;
+ init_logger(config.log_level, config.log_file.as_path())?;
let daemon = Daemon::new().chain_err(|| "Unable to initialize daemon")?;
@@ -471,8 +472,7 @@ fn run() -> Result<()> {
Ok(())
}
-fn init_logger(log_level: log::LogLevelFilter) -> Result<()> {
- let log_filename = "mullvadd.log";
+fn init_logger(log_level: log::LogLevelFilter, log_file: &Path) -> Result<()> {
fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!("{}[{}][{}] {}",
@@ -484,6 +484,6 @@ fn init_logger(log_level: log::LogLevelFilter) -> Result<()> {
})
.level(log_level)
.chain(std::io::stdout())
- .chain(fern::log_file(log_filename).chain_err(|| "Failed to open log file for writing")?)
+ .chain(fern::log_file(log_file).chain_err(|| "Failed to open log file for writing")?)
.apply().chain_err(|| "Failed to bootstrap logging system")
}